Show Menu

Docker and friends Cheat Sheet by

Commands to control docker and related technologies
development     linux     deployment     technology     cloud     sysadm     sysops

Building Images

docker build
Build a new image from the source code at PATH
docker build -t myimg .
-q
Suppress the output generated by containers
--rm
Remove interm­ediate containers after a successful build
-t
Repository name (and optionally a tag) for the image
Exam­ples:
Simplest possible build instru­ction:
docker build .
Name image and tag as v1.5:
docker build -t myorg/­myi­mg:1.5 .

Misc useful commands

attach
Attach to a running container
cp
Copy files/­folders from a contai­ner's filesystem to the host path
create
Create a new container
exec
Run a command in a running container
images
List images
export
Stream the contents of a container as a tar archive
import
Create a new filesystem image from the contents of a tarball
inspect
Return low-level inform­ation on a container or image
kill
Kill a running container
load
Load an image from a tar archive
logs
Fetch the logs of a container
port
Lookup the public­-facing port that is NAT-ed to PRIVAT­E_PORT
ps
List containers
pull
Pull an image or a repository from a Docker registry server
push
Push an image or a repository to a Docker registry server
rm
Remove one or more containers
rmi
Remove one or more images
save
Save an image to a tar archive
search
Search for an image on the Docker Hub
start
Start a stopped container
stop
Stop a running container
top
Lookup the running processes of a container
wait
Block until a container stops, then print its exit code
Run docker COMMAND --help for help on the command.
 

Running Docker

docker run
starts a process with its own file system, its own networ­king, and its own isolated process tree
docker run -itP image
--name
name the container
docker run --name­=so­mename org
-t
terminal interface
-i
intera­ctive session
-d
daemon Mode
-P
publish all exposed ports
-p
expose specific port
-p ip:hos­tpo­rt:­con­tai­ner­port
--rm
remove interm­ediate images
-v
bind mount a volume
-v /host:­/co­nta­iner
Exam­ples:
run an intera­ctive session:
sudo docker run -P --name­=so­mename image
run container in backgr­ound, on port 80:
sudo docker run --d -v /etc/a­ppd­ata­:/data -p 0.0.0.0­:8­0:8080 --rm nginx

Docker Compose

 
TBC
 

Docker­files (for creating images)

FROM
set base image for this image
FROM <im­age­>:<­tag­>
MAINT­AINER
The author of the image
MAINTAINER <na­me>
RUN
execute commands in new layer
RUN <command>
RUN ["ex­ecu­tab­le", "­par­am1­", ...]
CMD
provide default for an executing container
CMD ["ex­ecu­tab­le",­"­par­am1­"­,...]
LABEL
add metadata to image
LABEL <ke­y>=­<va­lue> <ke­y>=­<va­lue­>
EXPOSE
listen on the network ports
EXPOSE <po­rt> [<p­ort­>...]
ENV
set the enviro­nment variables
ENV <ke­y> <value>
ENV <ke­y>=­<va­lue> <ke­y>=­<va­lue­>
ADD ­/­C­OPY­??
copies new files from <s­rc> and adds them to the container at <dest>.
ADD <sr­c>... <de­st>
ENTRY­POINT
configure container to run as an executable
ENTRYPOINT ["ex­e", "­arg­"...]
VOLUME
create externally mounted volumes
VOLUME ["/d­ata­"]
USER
sets the user name or UID to use when running the image
USER<user>
WORKDIR
sets working dir for any RUN, CMD, ENTRY­POINT, COPY and ADD instructions:
WORKDIR /path/­to/­wor­kdir
ONBUILD
adds a trigger instru­ction for execution when image is used as base of another build
ONBUILD [INSTR­UCT­ION]
Check out the Manual Page for more detail.

Download the Docker and friends Cheat Sheet

2 Pages
//media.cheatography.com/storage/thumb/aabs_docker-and-friends.750.jpg

PDF (recommended)

Alternative Downloads

Share This Cheat Sheet!

 

Comments

javafun javafun, 12:57 6 Dec 16

PDF link is not working

Add a Comment

Your Comment

Please enter your name.

    Please enter your email address

      Please enter your Comment.

          Related Cheat Sheets

          mod_rewrite Cheat Sheet
          VI Editor Cheat Sheet