Docker command:docker run [options] image-name [command] [arg]
- Docker Cheat Sheet With Examples Download
- Docker Command Line Cheat Sheet
- Docker Command Cheat Sheet Pdf
- Docker Cheat Sheet With Examples Free
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:
- A docker swarm cheat sheet - learn about docker swarm, docker services, docker swarm nodes, docker swarm tasks and more all on one page!
- Docker Command Cheat Sheet with Examples. Published January 29, 2021 by hanif s. Last updated on February 11, 2021. Docker is a containerization system.
Docker Cheat Sheet With Examples Download
Docker Cheat Sheet is a document that provides the information of basic Docker commands and their details with examples. When you install Docker, you can check the document to get information on each and every command used in Docker.
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 Command Line Cheat Sheet
Example. Building an image from a Dockerfile in the current directory:docker build .
Docker Command Cheat Sheet Pdf
- 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 Cheat Sheet With Examples Free
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 |
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 |