Docker Cheat Sheet: Running a New Container
๐ Start a new Container from an Image
docker run IMAGE
docker run nginx
๐ท๏ธ Assign it a name
docker run --name CONTAINER IMAGE
docker run --name web nginx
๐ Map a port
docker run -p HOSTPORT:CONTAINERPORT IMAGE
docker run -p 8080:80 nginx
๐ Map all ports
docker run -P IMAGE
docker run -P nginx
๐ป Start container in the background
docker run -d IMAGE
docker run -d nginx
๐ Assign it a hostname
docker run --hostname HOSTNAME IMAGE
docker run --hostname srv nginx
๐ Add a DNS entry
docker run --add-host HOSTNAME:IP IMAGE
๐ Map a local directory into the container
docker run -v HOSTDIR:TARGETDIR IMAGE
docker run -v /:/usr/share/nginx/html nginx
๐ง Change the entrypoint
docker run -it --entrypoint EXECUTABLE IMAGE
docker run -it --entrypoint bash nginx
Docker Cheat Sheet: Manage Containers
๐ Show a list of running containers
docker ps
๐ Show a list of all containers
docker ps -a
โ Delete a container
docker rm CONTAINER
docker rm web
โ Delete a running container
docker rm -f CONTAINER
docker rm -f web
โ Delete stopped containers
docker container prune
โน๏ธ Stop a running container
docker stop CONTAINER
docker stop web
โถ๏ธ Start a stopped container
docker start CONTAINER
docker start web
๐ Copy a file from a container to the host
docker cp CONTAINER:SOURCE TARGET
docker cp web:/index.html index.html
๐ Copy a file from the host to a container
docker cp TARGET CONTAINER:SOURCE
docker cp index.html web:/index.html
๐ Start a shell inside a running container
docker exec -it CONTAINER EXECUTABLE
docker exec -it web bash
๐ Rename a container
docker rename OLD_NAME NEW_NAME
docker rename 096 web
๐ฆ Create an image out of container
docker commit CONTAINER
docker commit web
Docker Cheat Sheet: Manage Images
๐ฅ Download an image
docker pull IMAGE[:TAG]
docker pull nginx
๐ค Upload an image to a repository
docker push IMAGE
docker push myimage:1.0
โ Delete an image
docker rmi IMAGE
๐ Show a list of all images
docker images
โ Delete dangling images
docker image prune
โ Delete all unused images
docker image prune -a
๐๏ธ Build an image from a Dockerfile
docker build DIRECTORY
docker build .
๐ท๏ธ Tag an image
docker tag IMAGE NEWIMAGE
docker tag ubuntu ubuntu:18.04
๐๏ธ Build and tag an image from a Dockerfile
docker build -t IMAGE DIRECTORY
docker build -t myimage
๐พ Save an image to a tar file
docker save IMAGE > FILE
docker save nginx > nginx.tar
๐ฅ Load an image from a tar file
docker load -i TARFILE
docker load -i nginx.tar
Docker Cheat Sheet: Info & Stats
๐ Show the logs of a container
docker logs CONTAINER
docker logs web
๐ Show stats of running containers
docker stats
๐ Show processes of container
docker top CONTAINER
docker top web
๐ Show installed Docker version
docker version
๐ Get detailed info about an object
docker inspect NAME
docker inspect nginx
๐ Show all modified files in container
docker diff CONTAINER
docker diff web
๐ Show mapped ports of a container
docker port CONTAINER
docker port web
Celebrating the completion of hands-on sessions. ๐ Now, level up your Docker game with a unique cheat-sheet! ๐๐ก Share your knowledge on Docker and Docker-Compose commands to empower the DevOps community. ๐๐ Get creative, contribute, and let's spread the wisdom together! ๐๐