Basic Docker Cheat Sheet
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# Docker Image | |
## List all images | |
docker image ls | |
## Pull docker images | |
docker image pull image:tag | |
## Remove docker images | |
docker image rm image:tag | |
# Docker container | |
## Show all list of container | |
docker container ls -a | |
## Show only running container | |
docker container ls | |
# Create container | |
docker container create --name name image:tag | |
# Run container | |
docker container start containerID/containerName | |
# Stop container | |
docker container stop containerID/containerName | |
# Delete container | |
docker container rm containerID/containerName | |
# Container Log | |
## View container log | |
docker container logs containerID/containerName | |
## View container log with blocking | |
docker container logs containerID/containerName -f | |
# Exec container | |
docker container exec -i -t containerID/containerName /bin/bash | |
# Port forwarding | |
docker container create --name name -p phost:pcontainer -p phost:pcontainer image:tag | |
# Passing env variable | |
docker container create --name name -e KEY="value" -e KEY="value" image:tag | |
# See container stats | |
docker container stats | |
# Limit Resources | |
## Memory Allocation to container | |
docker container create --name name -m 180m image:latest | |
## CPUs allocation to container | |
docker container create --name name --cpus 0.5 image:latest | |
# Mounting folder | |
## type=bind,volume | |
docker container create --name name --mount "type=bind,source=folder,destination=folder,readonly" image:tag | |
# Docker Volume | |
## Show all volume | |
docker volume ls | |
## Create Volume | |
docker volume create name | |
## Delete volume | |
docker volume rm name | |
## Mounting volume | |
docker container create --name name --mount "type=volume,source=volname,destination=dest" image:tag | |
# Backup the volume | |
## Stopping target container | |
docker container stop targetname | |
## Create backup container | |
docker container create --name backupname --mount "type=bind,source=backupsource,destination=backupdest" --mount "type=volume,source=volname,destination=backupdest" image:tag | |
## Start and execute the backup container | |
docker container start backupname | |
docker container exec -i -t backupname /bin/bash | |
## Do backup inside backup container | |
tar cvf /backup/volname.tar.gz /backupdest | |
exit | |
## Stop and remove backup container | |
docker container stop backupname | |
docker container rm backupname | |
## Start again the target container | |
docker container start targetname | |
# Backup with shorthand | |
docker container run --rm --name ubuntu --mount "type=bind,source=srcHostDir,destination=destDir" --mount "type=volume,source=volname,destination=destDir" ubuntu:latest tar cvf /dstdir/backup.tar.gz /data | |
# Restore backup | |
docker container run --rm --name ubuntu --mount "type=bind,source=srcHostDir,destination=destDir" --mount "type=volume,source=volname,destination=destDir" ubuntu:latest bash -c "cd /data && tar xvf /destDir/backupFilename.tar.gz --strip 1" | |
# Network | |
## Show all network | |
docker network ls | |
## Create network | |
docker network create --driver driverName networkName | |
## Delete network | |
docker network rm networkName | |
# Container Network | |
## Create container with network | |
docker container create --name containerName --network networkName image:tag | |
# Docker Inspect | |
## Inspect the image | |
docker image inspect imageName | |
## Inspect the container | |
docker container inspect containerName | |
## Inspect the volume | |
docker volume inspect volName | |
## Insepct the network | |
docker network inspect networkName | |
# Docker Prune | |
## Prune the container | |
docker container prune | |
## Prune the image | |
docker image prune | |
## Prune the network | |
docker network prune | |
## Prune the volume | |
docker volume prune | |
## Prune all above | |
docker system prune |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Mantap ini bang