Docker Container Cheat Sheet

broken image


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
Docker cheat sheet pdf

Docker command:docker run [options] image-name [command] [arg]

Example: Running a container from the image alpine.

docker run image-namedocker run image-name commanddocker run image-name command arg
docker run alpinedocker run alpine lsdocker run alpine ping 192.168.3.1

Common options:

Docker Cheat Sheet 2020

Remove the container when it exitsGive the container a nameAllocate a terminal for the container
docker run --rm alpinedocker run --name toto alpinedocker run -it alpine
Mount data-volume at /data**Container port –> random host portHost port 8080 –> container port 80
docker run -v data-volume:/data alpinedocker run --P alpinedocker run -p 8080:80 alpine
Attach container to network
docker run --network mynet alpine
List all containersList running containersStop a container
docker container ls -adocker container lsdocker stop my-container
Remove a containerRemove all stopped containersStart a container
docker container rm my-containerdocker container prunedocker start my-container
Start a container (I/O)Inspect changes in a containerCreate image from container
docker start -ai my-containerdocker diff my-containerdocker 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 .

Docker Container Cheat Sheet
  • The command assumes that a file named Dockerfile is in the current directory.

Common options:

Docker Container Cheat Sheet
Tag the imageName of the Dockerfile
docker build -t my-image:latest .docker build -f my-dockerfile .
List all imagesList images (no intermediate)Remove an image
docker image ls -adocker image lsdocker image rm my-image
Remove dangling imagesRemove unused imagesShow the history of an image
docker image prunedocker image prune -adocker history my-image

In a Dockerfile the following main keywordsare used:

Cheat

Docker command:docker run [options] image-name [command] [arg]

Example: Running a container from the image alpine.

docker run image-namedocker run image-name commanddocker run image-name command arg
docker run alpinedocker run alpine lsdocker run alpine ping 192.168.3.1

Common options:

Docker Cheat Sheet 2020

Remove the container when it exitsGive the container a nameAllocate a terminal for the container
docker run --rm alpinedocker run --name toto alpinedocker run -it alpine
Mount data-volume at /data**Container port –> random host portHost port 8080 –> container port 80
docker run -v data-volume:/data alpinedocker run --P alpinedocker run -p 8080:80 alpine
Attach container to network
docker run --network mynet alpine
List all containersList running containersStop a container
docker container ls -adocker container lsdocker stop my-container
Remove a containerRemove all stopped containersStart a container
docker container rm my-containerdocker container prunedocker start my-container
Start a container (I/O)Inspect changes in a containerCreate image from container
docker start -ai my-containerdocker diff my-containerdocker 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 imageName of the Dockerfile
docker build -t my-image:latest .docker build -f my-dockerfile .
List all imagesList images (no intermediate)Remove an image
docker image ls -adocker image lsdocker image rm my-image
Remove dangling imagesRemove unused imagesShow the history of an image
docker image prunedocker image prune -adocker history my-image

In a Dockerfile the following main keywordsare used:

FROM base-imageFROM scratchRUN cmd
Specifies the base imageNo base image usedRuns a command
COPY src dstADD src dstWORKDIR dir
Copy source file to destinationCopy source file (including URL and TAR) to destinationSets the working directory
ENTRYPOINT cmdCMD paramsEXPOSE port
Command to execute when container is runParameters of the entrypoint commandExposes a container port

Docker Containers Download

Create a volumeRemove a volumeRemove unused volumes
docker volume create my-volumedocker volume rm my-volumedocker volume prune
List volumes
docker volume ls

Docker Compose Command Cheat Sheet

Create a networkRemove a networkRemove unused networks
docker network create my-networkdocker network rm my-networkdocker network prune
List all the networksInspect a networkConnect a container to a network
docker network lsdocker network inspect my-networkdocker network connect my-network my-container




broken image