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