Giter Club home page Giter Club logo

cheat-sheet-docker's Introduction

šŸ³ Docker Command Cheat Sheet

With docker installed, here are some common commands you will use. I have also provided some example code to check out.

Check available containers

docker ps

example output

CONTAINER ID   IMAGE          COMMAND                  CREATED         STATUS         PORTS                    NAMES
17f6f866d38c   446dbae429b7   "docker-entrypoint.sā€¦"   6 minutes ago   Up 6 minutes   0.0.0.0:8000->4000/tcp   festive_knuth

Create an Image

Breakdown

docker build -t [username]/[appname:version] [directory]

Example

docker build -t daltonhj/docker_example:1.0 . # the . here is current directory

Build Container

The run command actually builds the container and then starts it up.

Breakdown

docker run -d -p [local port]:[container port] [imageID]

Example

docker run -d --name myContainer -p 4000:4000 446dbae429b7

Stop Container

Breakdown

docker stop [container]

Example

docker stop myContainer

Restart Container

Breakdown

docker start [container]

Example

docker start myContainer

Create Volume

docker volumn create [volumn name]

Example

docker volumn create shared-stuff

Use a Volumne

docker run -d --name myContainer --mount source=shared-stuff,target=/stuff -p 4000:4000 446dbae429b7

Execute Commands Inside the Docker Container

Breakdown

docker exec [container name] [command to run]

Example

docker exec myContainer cat src/index.js

Want to access the bash terminal inside the container?

docker exec -it myContainer /bin/bash

Docker Compose

If you setup a docker-compose yaml file this will make things a lot easier as you will not need to run the above commands and allows you to define the commands for multiple containers in the same go.

With yaml file created to start up

docker-compose up -d

To spin up multiple containers per image

docker-compose up --scale [service]=[amount]

With yaml file to spin down

docker-compose down

cheat-sheet-docker's People

Contributors

simplysylvia avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    šŸ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. šŸ“ŠšŸ“ˆšŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ā¤ļø Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.