Appendix A — Docker Cheatsheet
A.1 General Docker Commands
Command | Purpose | Example |
---|---|---|
docker run |
Run an image as a container | docker run me/my-image |
docker ps |
List all containers | docker ps |
docker kill |
Kill a container | docker kill my-container |
docker exec |
Run a command inside a running container | docker exec -it /bin/bash |
docker build |
Build a Dockerfile | docker built -t me/my-image . |
docker logs |
Get logs from a container | docker logs my-container |
docker pull |
Pull a container from a registry | docker pull me/my-image |
docker push |
Push a container to a registry | docker push me/my-image |
A.2 docker run
command flags
Flag | Purpose | Example |
---|---|---|
-d |
Run in “detached” mode that doesn’t block your terminal | docker run -d ... |
--rm |
Remove the container on stop Reminder: don’t use in prod |
docker run --rm … |
-p |
Publish ports from container to host | docker run -p 8000:8000 … |
-v |
Mount a volume into the container | docker run -v $(pwd):/data |
--name |
Give container a human-friendly name | docker run --name my-container |
Reminder - -p
and -v
order is <host>:<container>
A.3 Dockerfile Commands
These are the commands that go in a Dockerfile when you’re building it.
Command | Purpose | Example |
---|---|---|
FROM |
Indicate base container | FROM rocker/r-ver:4.1.0 |
RUN |
Run a command when building | RUN apt-get update |
COPY |
Copy from the working directory into the container | COPY . /app/ |
CMD |
Specify the command to run when the container starts | CMD quarto render . |