Docker Flashcards
Keyword to inherit an image
FROM {image} [as {name}]
Keyword to provide defaults to an executing container
CMD
“exec” form of CMD
CMD [“executable”, “param1”, “param2”]
Form of CMD used to provide default parameters to ENTRYPOINT
CMD [“param1”, “param2”]
shell form of CMD
CMD executable param1 param2
Keyword for configuring a container which will run as an executable
ENTRYPOINT
“exec” form of ENTRYPOINT
ENTRYPOINT [“exe”, “param1”, “param2”]
(CLI)Run a new command in an existing container
docker exec -it {container} {cmd}
shell form of ENTRYPOINT
ENTRYPOINT exe param1 param2
(CLI) Override ENTRYPOINT given in Dockerfile
docker run –entrypoint {entry cmd}
(CLI) Connect to shell in new container
docker run -it {img}
(CLI) Run a new command in an existing container
docker exec -it {container} {cmd}
(CLI) Attach to stdio of running container
docker attach {container}
Keyword to execute command in new layer
RUN
“exec” form of RUN
RUN [“exe”, “param1”, “param2”]
shell form of RUN
RUN {cmd}
Keyword to adjust shell used by RUN
SHELL [“exe”, “param”]
Default shell used by RUN
[“/bin/sh”, “-c”]
Keyword to set the working directory
WORKDIR {path}
Default WORKDIR
/
Keyword to duplicate files from context into image
COPY
Additional capabilities of ADD over COPY
Retrieve from URL; Unpack local tar/bz2/xz archive
How to set user/group ownership w/COPY
COPY –chown {uid}:{guid}
Prevent invalidation of COPY layer on rebuild
COPY –link
Term for dockerfile in which multiple FROM statements are used
Multi-stage build
Argument to COPY used to move files between stages of a multi-stage build
FROM {image} As {name}
COPY –from {name}
Three types of storage mounts
Volumes, bind mounts, tmpfs mounts
“-v” Syntax for a volume mount
-v {vol_name}:{dest}:{options}
{vol_name} may be excluded for anonymous vol
”–mount” syntax for a volume mount
–mount type=volume,src={src},dest={dest},ro
The main keynames for use with the “–mount” switch
type; src; dest; ro; volume-opt
CLI command to create a new volume
docker volume create {vol_name}
CLI command to view volume info
docker volume inspect {vol_name}
CLI command to delete a volume
docker volume rm {vol_name}
CLI switch to create a tmpfs volume
–tmpfs {dest}
CLI switch to create a size limited tempfs volume
–mount type=tmpfs,dest={dest},tmpfs-size=xxx
Keyword to indicate that a volume should be expected/created at a particular container path
VOLUME [“/path”]
VOLUME /path
Keyword to set the default user for subsequent commands
USER {UID}[:{GID}]
Here-document syntax
RUN «EOF
apt-get update
apt-get install -y vim
EOF
Here-document syntax (non-default shell/interpreter)
RUN «EOF
#!/usr/bin/env python
print(“hello python”)
EOF
Create an inline file
COPY «-EOF /path/to/file
{content of file}
EOF
Keyword to inform docker of intent to listen on a port at runtime
EXPOSE
Default protocol for EXPOSE keyword
tcp
Syntax to EXPOSE tcp+udp port
EXPOSE {port}/tcp
EXPOSE {port}/udp
CLI flag to map EXPOSED ports to ephemeral high-ordered ports
-P
CLI flag to map a port
-p 80:80/tcp -p 80:80/udp
Magic file listing files to be excluded from context
.dockerignore
Magic file listing files to be excluded from context
.dockerignore
Keyword to set an environment variable within build and run stages
ENV {key}={val}
ENV {key} {val}
CLI syntax to override an environment variable at runtime
docker run –env {key}={val}
Keyword to set an environment variable within only the run stage
ARG {key}[={default_val}]
CLI syntax to override a build arg at build time
docker build –build-arg {key}={val}
Syntax to use a ENV/ARG variable in a RUN command
RUN echo $var_name
Statement to clear an inherited ENTRYPOINT
ENTRYPOINT []
How to give a container USB access
docker run -it –privileged -v /dev/bus/usb:/dev/bus/usb {container} {cmd}