Docker Cheatsheet
Overview
Managing Images | ||
docker build |
create an image from a Dockerfile | |
Managing Containers | ||
docker run <image> |
create + start | |
docker create <image> |
create the container, without starting | |
docker start <container> |
create + start the container | |
docker stop <container> |
SIGTERM | |
docker kill <container> |
SIGKILL | |
docker restart <container> |
stop + start | |
docker pause / unpause <container> |
suspend / resume the containter | |
docker rm [-f] <container> |
destroy te container | |
Inspecting containers | ||
docker ps [-a] |
list the containers | |
docker log <container> |
show the container output | |
docker top <container> |
top the container processes |
|
docker diff <container> |
show all modified files in container | |
docker inspect <container> |
show low-level infos | |
Interacting with containers | ||
docker cp <src> <dst> |
copy the file from/into container | |
docker attach <container> |
attach io to a running container | |
docker export <container> |
export the content of the container to tar archive | |
docker exec <container> <args> |
run a command in the container | |
docker wait <container> |
wait until the container terminates and return the exit code | |
docker commit <container> <image> |
take a snapshot of the container | I |
Imagae management | ||
docker images |
list of all local images | |
Dockerfile | ||
FROM <IMAGE>/SCRATCH |
base image | |
MAINTAINER <EMAIL> |
mainainter info | |
USER <NAME> |
default username | |
WORKDIR <PATH> |
default working directory | |
CMD <ARGS> |
set the default command | |
ENV <NAME> <VALUE> |
set an environemtn variable | |
COPY <PATH> <DST> |
copy <PATH> from the context into the container <DST> |
|
ADD <SRC> <DST> |
<SRC> could be URLs |
|
RUN <ARGS> |
run the command in the container |
Create an image <a name=”build’ href=’#overview’></a>
Create an image with tag name
docker build . -t "app/container_name"
Run a new Container
docker run
by default has stdout stream connected. -i
make the container wait for interaction from host, and -t
allocates pseudo-tty driver for the host.
Start a new container from an Image
docker run --name my_container image
Mapping a port
docker run -P <HOSTPORT>:<CONTAINERPORT> image
Detach the io (run in background)
docker run -d image
Assign a hostname
docker run --hostname _hostname image
Create a container
Creat a container from an image, with a name
docker create --name my_container image:tag
List of containers
List of all (running + stopped) containers
docker ps -a
Filter the containter
docker ps -f"name=something"
Delete a container
docker rm <CONTAINER> # -f force quit
Delete all stopped container
docker container prune
Start a container
docker start <CONTAINER>
Stop a container
docker stop <CONTAINER>
Manage Images
Start a new container from an Image