Docker delivers software in containers, which simplifies the process by packaging everything it takes to run an application. With Docker growing in popularity, it becomes necessary to understand it before using it on your own or for a business. Windows Containers (personal) cheat sheet. The container had nothing exposed to the standard output, so when you started the container or tried to see the logs via docker logs nothing was there. Build docker image PS cd path to Dockerfile PS docker build. View running processes. PS docker ps View all processes. PS docker ps -a Run an image in a new container daemonized. PS docker run -d Run an image in interactive mode with the command powershell.exe. PS docker run -i -t powershell.exe. Docker cheat sheet Introduction. Docker is a tool for bundling together applications and their dependencies into images that can than be run as containers on many different types of computers.
Docker command:docker run [options] image-name [command] [arg]
Example: Running a container from the image alpine.
docker run image-name | docker run image-name command | docker run image-name command arg |
docker run alpine | docker run alpine ls | docker run alpine ping 192.168.3.1 |
Common options:
Docker Cheat Sheet 2020
Remove the container when it exits | Give the container a name | Allocate a terminal for the container |
docker run --rm alpine | docker run --name toto alpine | docker run -it alpine |
Mount data-volume at /data** | Container port –> random host port | Host port 8080 –> container port 80 |
docker run -v data-volume:/data alpine | docker run --P alpine | docker run -p 8080:80 alpine |
Attach container to network | ||
docker run --network mynet alpine |
List all containers | List running containers | Stop a container |
docker container ls -a | docker container ls | docker stop my-container |
Remove a container | Remove all stopped containers | Start a container |
docker container rm my-container | docker container prune | docker start my-container |
Start a container (I/O) | Inspect changes in a container | Create image from container |
docker start -ai my-container | docker diff my-container | docker commit my-container new-image |
Docker command:docker build [OPTIONS] PATH | URL
Docker Container Cheat Sheet Pdf
Example. Building an image from a Dockerfile in the current directory:docker build .
- The command assumes that a file named Dockerfile is in the current directory.
Common options:
Tag the image | Name of the Dockerfile |
docker build -t my-image:latest . | docker build -f my-dockerfile . |
List all images | List images (no intermediate) | Remove an image |
docker image ls -a | docker image ls | docker image rm my-image |
Remove dangling images | Remove unused images | Show the history of an image |
docker image prune | docker image prune -a | docker history my-image |
In a Dockerfile the following main keywordsare used:
Docker command:docker run [options] image-name [command] [arg]
Example: Running a container from the image alpine.
docker run image-name | docker run image-name command | docker run image-name command arg |
docker run alpine | docker run alpine ls | docker run alpine ping 192.168.3.1 |
Common options:
Docker Cheat Sheet 2020
Remove the container when it exits | Give the container a name | Allocate a terminal for the container |
docker run --rm alpine | docker run --name toto alpine | docker run -it alpine |
Mount data-volume at /data** | Container port –> random host port | Host port 8080 –> container port 80 |
docker run -v data-volume:/data alpine | docker run --P alpine | docker run -p 8080:80 alpine |
Attach container to network | ||
docker run --network mynet alpine |
List all containers | List running containers | Stop a container |
docker container ls -a | docker container ls | docker stop my-container |
Remove a container | Remove all stopped containers | Start a container |
docker container rm my-container | docker container prune | docker start my-container |
Start a container (I/O) | Inspect changes in a container | Create image from container |
docker start -ai my-container | docker diff my-container | docker commit my-container new-image |
Docker command:docker build [OPTIONS] PATH | URL
Docker Container Cheat Sheet Pdf
Example. Building an image from a Dockerfile in the current directory:docker build .
- The command assumes that a file named Dockerfile is in the current directory.
Common options:
Tag the image | Name of the Dockerfile |
docker build -t my-image:latest . | docker build -f my-dockerfile . |
List all images | List images (no intermediate) | Remove an image |
docker image ls -a | docker image ls | docker image rm my-image |
Remove dangling images | Remove unused images | Show the history of an image |
docker image prune | docker image prune -a | docker history my-image |
In a Dockerfile the following main keywordsare used:
FROM base-image | FROM scratch | RUN cmd |
Specifies the base image | No base image used | Runs a command |
COPY src dst | ADD src dst | WORKDIR dir |
Copy source file to destination | Copy source file (including URL and TAR) to destination | Sets the working directory |
ENTRYPOINT cmd | CMD params | EXPOSE port |
Command to execute when container is run | Parameters of the entrypoint command | Exposes a container port |
Docker Containers Download
Create a volume | Remove a volume | Remove unused volumes |
docker volume create my-volume | docker volume rm my-volume | docker volume prune |
List volumes | ||
docker volume ls |
Docker Compose Command Cheat Sheet
Create a network | Remove a network | Remove unused networks |
docker network create my-network | docker network rm my-network | docker network prune |
List all the networks | Inspect a network | Connect a container to a network |
docker network ls | docker network inspect my-network | docker network connect my-network my-container |