Docker Cheat Sheet
Docker Cheat Sheet
Commands
Note is either a container id, or a container name (if such is given to a container with the --name
option on start). Both can be obtained with the "docker ps -a" command. is either an image
id, or an image name. Both can be obtained with the "docker image" command. Do not confuse
with container id/name!
docker run -i -t ubuntu /bin/bash # New instance from image. "-i" is for
"interactive" and "t" is for terminal. Without "it" it
# won't be interactive - you will get a
shell/terminal, but will not be able to type anything onto
# it. Without "t" you will not get a terminal
opened. The command will run and exit.
docker run -i -t --rm ubuntu /bin/bash # If you need a one-time container, then use
the --rm option. Thus, once you exit the container,
# it will be removed
Dockerfile Examples
Installing packages
FROM debian:wheezy
RUN apt-get update
RUN apt-get -y install python git
Adding users
WORKDIR /home/jsmith/
ENV HOME /home/jsmith
Mounts
VOLUME ["/home"]
Opening ports
EXPOSE 22
EXPOSE 80
Start command
USER jsmith
WORKDIR /home/jsmith/
ENTRYPOINT bin/my-start-script.sh
Setting timezone
ENV TZ=America/Los_Angeles
RUN ln -snf /usr/share/zoneinfo/$TZ /etc/localtime && echo $TZ > /etc/timezone
Multi-stage Dockerfiles
FROM image1
...
FROM image2
...
Above syntax example will automatically trigger two builds. Stages also can be named:
Misc