Day 19: Docker Cheat-sheet
I am Yashraj Singh Sisodiya, a 3rd Year CSE student at SVVV, born and raised in Shujalpur. Currently residing in Indore, I'm passionate about pursuing a career in DevOps engineering. My tech journey began with an internship at Infobyte, honing my skills as an Android Developer intern. Alongside my academic pursuits, I actively participate in co-curriculars, holding roles as Technical Lead at Abhyudaya and Cloud Lead at GDSC SVVV, while also serving as an MLSA of my college.
I have a keen interest in Cloud Computing, demonstrated through projects such as User management and Backup using shell scripting Linux, Dockerizing applications, CI/CD with Jenkins, and deploying a 3-tier application on AWS. Always eager to learn, I'm committed to expanding my knowledge and skills in the ever-evolving tech landscape.
General Usage
Start a container in the background:
$ docker run -d jenkinsStart an interactive container:
$ docker run -it ubuntu bashExport port from a container:
$ docker run -p 80:80 -d nginxStart a named container:
$ docker run --name mydb redisRestart a stopped container:
$ docker start mydbStop a container:
$ docker stop mydbAdd metadata to a container:
$ docker run -d --label=traefik.backend=jenkins jenkins
Build Images
Build an image from Dockerfile in the current directory:
$ docker build --tag myimage .Force rebuild of a Docker image:
$ docker build --no-cache .Convert a container to an image:
$ docker commit c7337 myimage
Debug
Run another process in a running container:
$ docker exec -it c7337 bashShow live logs of a running daemon container:
$ docker logs -f c7337Show exposed ports of a container:
$ docker port c7337
Volumes
Create a local volume:
$ docker volume create --name myvolMounting a volume on container start:
$ docker run -v myvol:/data redisDestroy a volume:
$ docker volume rm myvolList volumes:
$ docker volume ls
Manage Containers
List running containers:
$ docker psList all containers (running & stopped):
$ docker ps -aDelete all stopped containers:
$ docker rm $(docker ps --filter status=exited -q)Start a container automatically removed on stop:
$ docker run --rm ubuntu bashQuery a specific metadata of a running container:
$ docker inspect -f '{{ .NetworkSettings.IPAddress }}' c7337
Networking
Create a local network:
$ docker network create mynetAttach a container to a network on start:
$ docker run -d --net mynet redisConnect a running container to a network:
$ docker network connect mynet c7337Disconnect a container from a network:
$ docker network disconnect mynet c7337List all containers with a specific label:
$ docker ps --filter label=traefik.backend
Cleanup
Remove all unused images:
$ docker rmi $(docker images -q)




