Skip to content

Instantly share code, notes, and snippets.

@cecyc
Last active January 17, 2019 23:48
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save cecyc/258b900701e2a93b7e59 to your computer and use it in GitHub Desktop.
Save cecyc/258b900701e2a93b7e59 to your computer and use it in GitHub Desktop.
Docker command cheatsheet

General

docker ps

Give me a list of all containers and their status.

docker inspect CONTAINER

Give me information about a container (you can find ip address and other info).

Working with images

Get image and run

This runs an image and will download if you don't already have it.

docker run REPONAME:latest

Get image, run, remove

If you want to run an image but you don't want to keep it.

docker run --rm REPONAME:latest

Pull images

docker pull IMAGE_NAME or docker pull USERNAME/IMAGE_NAME

For private images, you need the full path docker pull URL

Remove all containers

docker rm $(docker ps -a -q)

Remove images

docker rmi IMAGE ID

Can also just type the first 4 characters of the IMAGE ID

New Rails project based on Rails image

Dockerhub has you run this command $ docker run -it --rm --user "$(id -u):$(id -g)" -v "$PWD":/usr/src/app -w /usr/src/app rails rails new --skip-bundle NAME BUT if you are on Mac OS X, using Docker Toolbox, you need to remove the --user "$(id -u):$(id -g)" if you get an error. So, use this instead: docker run -it --rm -v "$PWD":/usr/src/app -w /usr/src/app rails rails new --skip-bundle NAME

Docker Machine

(Deprecated if you're using Docker native.)

docker-machine ls lists all machines running docker-machine rm [NAME] removes the machine named docker-machine create [OPTIONS] will create a new machine

Docker Compose

docker-compose build will build your project if this is your first time getting it setup. If you make changes to your Dockerfile, you will need to re-run docker-compose build.

docker-compose up will download images and setup containers as specified in docker-compose.yml. This will also link containers that need to be linked. You can run this in the background by using the -d tag (i.e. detached).

docker-compose down will remove any images and containers in the project.

--remove-orphans use this flag to remove any orphan containers when composing up or down.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment