Cheatography
https://cheatography.com
Commands to control docker and related technologies
Building Imagesdocker build
| Build a new image from the source code at PATH
docker build -t myimg . | -q
| Suppress the output generated by containers | --rm
| Remove intermediate containers after a successful build | -t
| Repository name (and optionally a tag) for the image |
Examples:
Simplest possible build instruction:
docker build .
Name image and tag as v1.5:
docker build -t myorg/myimg:1.5 .
Misc useful commandsattach | Attach to a running container | cp | Copy files/folders from a container'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 information 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 PRIVATE_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 Dockerdocker run
| starts a process with its own file system, its own networking, and its own isolated process tree
docker run -itP image | --name
| name the container docker run --name=somename org | -t
| terminal interface | -i
| interactive session | -d
| daemon Mode | -P
| publish all exposed ports | -p
| expose specific port
-p ip:hostport:containerport | --rm
| remove intermediate images | -v
| bind mount a volume
-v /host:/container |
Examples:
run an interactive session:
sudo docker run -P --name=somename image
run container in background, on port 80:
sudo docker run --d -v /etc/appdata:/data -p 0.0.0.0:80:8080 --rm nginx
| | Dockerfiles (for creating images)FROM
| set base image for this image
FROM <image>:<tag> | MAINTAINER
| The author of the image
MAINTAINER <name> | RUN
| execute commands in new layer
RUN <command>
RUN ["executable", "param1", ...] | CMD
| provide default for an executing container
CMD ["executable","param1",...] | LABEL
| add metadata to image
LABEL <key>=<value> <key>=<value> | EXPOSE
| listen on the network ports
EXPOSE <port> [<port>...] | ENV
| set the environment variables
ENV <key> <value>
ENV <key>=<value> <key>=<value> | ADD /COPY ??
| copies new files from <src> and adds them to the container at <dest> .
ADD <src>... <dest> | ENTRYPOINT
| configure container to run as an executable
ENTRYPOINT ["exe", "arg"...] | VOLUME
| create externally mounted volumes
VOLUME ["/data"] | USER
| sets the user name or UID to use when running the image
USER<user> | WORKDIR
| sets working dir for any RUN , CMD , ENTRYPOINT , COPY and ADD instructions:
WORKDIR /path/to/workdir | ONBUILD
| adds a trigger instruction for execution when image is used as base of another build
ONBUILD [INSTRUCTION] |
|
Created By
aabs.wordpress.com
Metadata
Favourited By
Comments
PDF link is not working
Add a Comment
Related Cheat Sheets