Docker cheat sheet ❯ https://goo.gl/uRWLFS
Useful tips & tricks to learn build and deploy your distributed applications easily to the cloud with Docker !
- Want to improve this cheat sheet ? your PRs are welcome
- With ❤️ by Ouadie LAHDIOUI
- Check the installation guide for your platform
docker version
docker -v
docker info
docker ps
Shows all containers that are currently runningdocker ps -a
Shows all containersdocker images
: See a list of all images on your systemdocker rm <CONTAINER_ID> <CONTAINER_ID>
Remove containers by iddocker rmi <IMAGES_ID> <IMAGES_ID>
Remove images
docker run [options] [image] [process]
docker run hello-world
Verify your systemdocker run busybox
Run a Docker container based on an imagedocker run busybox echo "hello from busybox"
Run an empty command and then exitdocker run --rm <CONTAINER_ID>
Start a container automatically removed on stopdocker pull <IMAGE_ID>
Fetches the busybox image from the Docker registry and saves it to your systemdocker start <CONTAINER_ID>
Restart a stopped containerdocker stop <CONTAINER_ID>
Stop a container
docker run -it busybox sh
Run a container in interactive mode (type exit to close)docker run -t -i ubuntu /bin/bash
launch an Ubuntu container and install what you want inside (Ex: apt-get update && apt-get install apache2)
docker run -d <CONTAINER_ID>
docker commit <CONTAINER_ID> ouadie/busybox
docker rm <CONTAINER_ID>
Remove a containerdocker rmi <IMAGE_ID>
Remove imagesdocker rm $(docker ps -a -q)
Remove all containersdocker rmi $(docker ps -a -q)
Remove all images
docker build --tag myimage .
Build an image from Dockerfile in current directory
docker run -d -p 80:80 coreos/apache /usr/sbin/apache2ctl -D FOREGROUND
docker exec -it <CONTAINER_ID> /bin/bash
docker push coreos/apache
Push to the public registrydocker push registry.example.com:5000/apache
Push to a private registry
- Sign up for an account
- Add a new repository, for example : https://hub.docker.com/r/ouadie/docker-cheatsheet
docker tag <IMAGE_ID> ouadie/docker-cheatsheet:latest|v1.0
Tag your docker image usingdocker login
Log indocker push ouadie/docker-cheatsheet
Push your imagedocker search tomcat
Search for an image
Dockerfile allows developers to build Docker images automatically. It contains a list of commands.
It has the format :
INSTRUCTION arguments
INSTRUCTION is not case-sensitive but convention says it ought to be uppercase to be easily distinguished from arguments.
Main commands :
FROM imageName[:version]
imageName is the name of the Docker Image in docker hub. If the version is not specified, Docker takes the latest.MAINTAINER creator
Information about the creator of the image. (deprecated)COPY <src> <dest>
This command copies files or directories fromsrc
to the filesystem of the container atdest
. If all files should be copied, src can be : "."RUN <command>
orRUN ["exec", "param1", "param2"]
Commands are in shell form or exec form.CMD <command>
Commands in RUN are also in shell and exec form. In a Dockerfile, only one CMD instruction should be written, otherwise, only the last one will taken into consideration. It is the process to execute.EXPOSE <port> [<port> ...]
At runtime, the container will listen on the specified ports.ENV <key> <value>
ENV sets the environement variablekey
to the valuevalue
.
Build :
docker build -t appName .
Build Docker image using the Dockerfile in the root of the context.
docker build -f path/to/Dockerfile .
Use-f
to build a Docker image from anywhere in your file system.