Cheatography
https://cheatography.com
Docker CLI using the latest format
This is a draft cheat sheet. It is a work in progress and is not finished yet.
Container Running
Run a new container |
docker container run [options] IMAGE[:TAG] [COMMAND] |
Options |
--rm |
remove container on exit |
--name |
add container ID |
-e |
set environment variable |
-p |
publish container ports to host |
--network |
connect container to network |
--net-alias |
network scoped alias for the container |
-d |
container in background / detached |
-it |
run interactively |
-v=[host-src:]container-dest[:<options>]
|
Volume |
|
map the pwd into the '/app' folder |
Start an existing Container |
docker container start [container]
|
|
|
Stop a running container |
docker container stop [container]
|
Kill a running container |
docker container kill [container]
|
Container Management Commands
List containers |
|
|
Create a container |
docker container create [OPTIONS] IMAGE
|
Remove a container |
|
|
force removal of running container |
Remove all stopped containers |
|
List processes in specific container |
docker container top [container]
|
Show logs on specific container |
docker container logs [container]
|
List docker container commands |
|
Container commands
start a new container interactively |
|
Run additional process in running container |
docker container exec CONTAINER [CMD]
|
docker container exec -it my_alpine ping my_ubuntu
|
docker container run --rm --net bcs alpine nslookup search
|
List of ports forwarding traffic from host to container |
docker container port [container]
|
Display detailed container information |
|
|
|
Management
What version |
|
Configuration values for the docker engine |
|
List of all commands |
|
Networks
List network |
|
Inspect network |
|
Create a network |
docker network create [network]
|
Attach a network to container |
docker network connect [network] [container]
|
Detach a network from container |
docker network disconnect [network] [container]
|
Images
List images |
|
Re-tag an image |
docker image tag SOURCE_IMAGE[:tag] TARGET_IMAGE[:tag]
|
Log in to registry (the Docker Hub by default) |
|
Push an image to the registry |
docker push [options] NAME[:TAG]
|
Pull an image |
docker pull [options] NAME[:TAG]
|
Build an image from a Dockerfile |
docker image build [OPTIONS] PATH
|
|
Docker File - image recipies
Set the base image for further instructions |
|
Set environment variables |
|
Set instruction to execute |
RUN <command> [&& <command>]
|
Set the ports that the container listens on |
EXPOSE <port> [<port>/<protocol>...]
|
Default command for executing container |
CMD ["executable", "param1", "param2"]
|
Working directory changed for later instructions |
WORKDIR /path/to/workdir
|
Copy files |
COPY [--chown=<user>:<group>] <src>... <dest>
|
|
|
Docker Volume
Where does the container keep the volume? |
docker container inspect [options] CONTAINER
|
Detailed information on one or more volume |
docker volume inspect [OPTIONS] VOLUME
|
List volumes |
docker volume ls [OPTIONS]
|
Remove all unused local volumes |
|
Docker Compose
Start system |
|
--build
- rebuild container |
-d
detach/launch in background |
Stop and Remove system |
|
List containers |
|
|