⭐ Docker Cheatsheet ⭐
This Repository is a guide to all the Docker CLI commands you need to use in case any of these situations arise
Index 📚
Create Containers ✨
-
Create container from image and start it
> docker container run <image name>NOTE: Replace <image name> with required image name ignoring <>
-
Create container from image but not run it
> docker container create <image name>NOTE: Replace <image name> with required image name ignoring <>
Start Container 🏃
-
Start container which is currently not running
> docker container start <container id>NOTE: Replace <container id> with target container id ignoring <>
-
Start container which is currently not running and show output
> docker container start -a <container id>NOTE: Replace <container id> with target container id ignoring <>
-
Start container with shell access (ssh style)
> docker container run -it <container_id> shNOTE: Replace <container_id> with target container id ignoring <>
-
Start container with port mapping
> docker container run -p <to_port:from_port> <image_name>NOTE: Replace <image_name> with target image name and replace to_port with the port you want to access from your machine and replace from_port with the port in which the container uses
Ignore <>
Stop Running Container 🔴
-
Stop container after executing
> docker container stop <container id>NOTE: Replace <container id> with target container id ignoring <>
-
Intstantly terminate running container (force stop)
> docker container kill <container id>NOTE: Replace <container id> with target container id ignoring <>
Container Management 💼
-
View list of all running containers
> docker container lsNOTE: Add parameter -a to list all containers ever created
-
Remove all stopped containers from list
> docker system prune-
Clear list
> docker system prune --all-
Remove specific container from list
> docker container rm <continer_id>NOTE: Replace <container_id> with target container id ignoring <>
This might fail if the container is currently running. In that case view force delete command below
-
Force delete container from list
> docker container rm -f <container_id>NOTE: Replace <container_id> with target container id ignoring <>
Logs 📃
-
View specific container logs
> docker container logs <container id>NOTE: Replace <container id> with target container id ignoring <>
Dockerfile 🐳
-
Set base image
FROM <image>NOTE: Replace <image> with base image
-
Set Author Name
MAINTAINER <name>NOTE: Replace <name> with the name you want to set for the author field
-
Execute shell command
RUN <command>NOTE: Replace <command> with the command you want to execute on the containers shell
Click here to visit the repository containing language and framework specific templates for docker and docker compose
Contributors
|
Gowtham Karthikeyan |

