This is the Day 20 of the #90DaysofDevOps challenge in which we are going to summarize all the Docker commands in a single blog i.e you can say this is the CHEATSHEET of the docker.
Docker Commands :
sudo apt-get install docker.io
- This command will install the docker on your machine.
docker --version
- By executing this command you will get the docker version that is present on your system.docker images
- This command will show the images that you had pulled from the DockerHub. (Official platform of Docker that will store the registries or images)docker images -q
- This command will print only the image ID by executing the command with the -q option.docker tag <Image-name>:<version> username/give name to the image
- This command is used to give uniqueness to your own image. Here in the username better to give the name of the DockerHub username.docker push <Image-name>
- This command will push the image to the DockerHub.docker pull <Image-name>
- This command will push the image to the DockerHub.docker rmi -f <image-name>
- This command will delete the image.docker rmi $(docker images)
- This command will delete all the images in a single command.docker ps
- This command will print the containers that are running.docker ps -a
- This command will print all the containers that are running as well as exited containers.docker ps -a -q
- This command will show all the container ID.docker run --name <Container-name> <image-name>
- This command will create the container of the given image in foreground mode.docker run -d --name <container-name> -p 8000:8000 <image-name>
- This command will create the container in detached mode (-d) i.e in background mode with the (-p) port number 8000.docker start/stop <Container ID/Name>
- This command will start and stop the containers.docker exec -it <Container ID/Name> /bin/bash
- By this command, you can enter into a container. (-it) means interaction mode. As the container has its unique name so the user is using/bin/bash
shell for logging in the shell.docker run -d --name <Container-name> --restart-always <Image-name>
- When you stop the Docker Host machine then it will automatically stop all the containers so by not executing the start command to start the containers always, we use this command that when we start the Docker Host machine it automatically starts all the docker containers. This will set the restart policy to always.docker inspect <Container ID/Name>
- By this command, you can inspect the containers.docker rm -f <Container ID/Name>
- This command will delete the containers.docker rm $(docker ps -a)
- This command will delete all the containers.docker load
- This command will be used to load the tar archive of the image.docker save
- This command will save an image to the tar archive.docker login
- This command is used to login into DockerHub.docker build -t <Image-name>:<version> .
- This command will build the image that is given in the Dockerfile. (-t) is the target image. In Image-name give your image name that is going to be your image.docker-compose --version
- This command will tell you the docker-compose version.docker-compose up
- This command will run the docker-compose file in foreground modedocker-compose up -d
- This command will run the docker-compose file in detach mode.docker-compose down
- This command will down all the containers that are created by the docker-compose file.sudo usermod -a -G docker $USER
- This command will assign permission to the user that will give the root access.docker logs <Container ID/Name>
- To view the logs of the given docker container ID/Name.docker port <container ID/Name>
- This command will give the ports of the container.docker stats <container ID/Name>
- This command will give the live usage of the containers.docker volume create <volume-name>
- This command will create the volume for the container.docker volume ls
- This command will list all the volumes.docker volume inspect <volume-name>
- This command will inspect the volume that you created and by this, you can see which container is attached to your volume.docker run -d --mount source=<volume-name>,destination=<destination-name> <Image-Name>
- This command will attach the volume to your container.docker volume prune
- This command will delete all the volumes.docker network ls
- To see all the networks that are created and present on your docker-machine.docker network create --driver <driver-name> <Network-name>
- This command will create the network with the given driver. I had covered all the topics of docker volume and network in my previous blogs.docker run -d --name <Container-name> --net=<Image-name> <Image-name>
- This command will create the container in the detach mode on your created network.docker network inspect <network-name>
- By this command, you can inspect your created network and see which container is attached to your network.docker network connect <network-name> <Container-name>
- This command will connect your created network with the container.docker network disconnect <network-name> <Container-name>
- This command will disconnect the created network from the attached container.docker network rm <network-name>
- This command will delete the network.
So, this is the cheat sheet of Docker Commands. I hope I covered all the docker commands and gave a better explanation of the commands.
Follow me on Hashnode for more Linux and DevOps Blogs !!
You can connect with me on Twitter (@amitmau07) !!