Day 20 - Docker Mastery Unlocked! ๐Ÿณโœจ

Day 20 - Docker Mastery Unlocked! ๐Ÿณโœจ

ยท

3 min read

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! ๐Ÿš€๐ŸŒ

Did you find this article valuable?

Support Nilkanth Mistry by becoming a sponsor. Any amount is appreciated!

ย