Day 20: 90DaysOfChallenge

Day 20: 90DaysOfChallenge

Docker Cheat Sheet

Here's a comprehensive cheat sheet of all the commands we have learned so far.

CommandDescription
Manage Images
docker imagesUsed to show the list of all the images
docker pull <image-name>Used to pull the docker image from docker repository(Docker Hub). Ex- docker pull mysql:latest
docker push <image-name>Used to push the docker image to the repository(Docker Hub). Ex- docker push my-image
docker rmi <image-name>Used to delete the image. Ex- docker rmi my-image
docker image pruneUsed to delete all the dangling images
docker image prune -aUsed to delete all the unused images
docker build directoryUsed to build an image from a Dockerfile. Ex- docker build .
docker build directory -t image-nameUsed to build and tag an image from Dockerfile. Ex- docker build . -t nginx:latest
Manage Containers
docker run <image-name:tagname>Used to start a new container from the image. Ex- docker run mysql:latest
docker run -d <image-name>Used to start a new container from the image but detach it from the system and then run. Ex- docker run -d mysql:latest
docker run --name container <image-name>Used to start a new container from the image and assign a name to the container. Ex- docker run --name my_database mysql:latest
docker run -p hostport:containerport imageUsed to start a new container from the image and map a port. Ex- docker run -p 8000:8000 nginx
docker psUsed to show all the running containers
docker ps -aUsed to show all the containers - running and stopped both
docker rm containerUsed to delete a container. Ex- docker rm container-id
docker container pruneUsed to delete all the stopped containers
docker stop containerUsed to stop the running container. Ex- docker stop container-id
docker start containerUsed to start the running container. Ex- docker start container-id
docker exec -it container bashUsed to start a shell inside a running container.Ex-docker exec -it container-id bash
docker rename <oldname><newname>Used to rename a container with a new one. Ex- docker oldname newname
docker kill container-idUsed to kill the running container. Ex- docker kill container-id
Info & Stats
docker logs containerUsed to show the logs of a container
docker versionUsed to show the version of installed docker
docker inspect nameUsed to show the detailed info about an object.
Volumes
docker volume lsUsed to show the list of all volumes
docker volume create --name <volume-name>Used to create a volume and assign name to the volume
Docker-compose
docker-compose upUsed to create and start multiple containers
docker-compose up -dUsed to create and start multiple containers in detach mode
docker-compose downUsed to kill and stop multiple containers

Thanks!

Happy Learning!

~Shilpi