Cheat Sheet Docker



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

Example: Running a container from the image alpine.

Docker Cheat Sheet Process Management # Show all running docker containers docker ps # Show all docker containers docker ps -a # Run a container docker run: # Run a container and connect to it docker run -it: # Run a container in the background docker run -d: # Stop a container docker stop. Download the Docker Cheat Sheet PDF. Our one-page Docker cheat sheet contains all the useful one-liners, Docker commands, syntax, and tips for interacting with a container that can all fit on one page. Be sure to download the pdf version by clicking the button below. Download the Cheat Sheet. Other Java Development Cheat Sheets. If Docker encounters a label/key that already exists, the new value overrides any previous labels with identical keys. To view an image’s labels, use the docker inspect command. They will be under the 'Labels' JSON attribute. Reference - Best Practices. This Docker cheat sheet will give you a quick reference to the basics of Docker that you must know to get started with it. Watch this Docker Tutorial for Beginners video: At Intellipaat, we support our learners with a handy reference, that’s the reason we have created this cheat sheet.

Cheat Sheet Docker
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:

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
Docker
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

Pdf

Example. Building an image from a Dockerfile in the current directory:docker build .

Docker Cheat Sheet For Spring Developers

  • 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 .
Cheat Sheet Docker
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

Cheat Sheet Docker

Create a volumeRemove a volumeRemove unused volumes
docker volume create my-volumedocker volume rm my-volumedocker volume prune
List volumes
docker volume ls
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