Docker Commands List Docker Commands Cheat Sheet-DecodingDevOps
Docker Commands List-Docker Commands Cheat Sheet
Docker is a software which packages the application and its dependencies in docker images. image contains files like operating system files, application files and dependencies. you can think like docker images are templates of virtual machines. with this images you can create containers(virtual-machines). by running the these docker images we create containers and in this containers applications will run.
Pull The Docker Images
as i said we need docker images to run docker containers. these docker images will be available or located in docker registry or dockerhub. To get these images to your system you have to pull the images from dockerhub, for this we use docker pull command.
to pull the docker image we use docker pull command
docker pull <docker-image>
$ docker pull nginx Using default tag: latest latest: Pulling from library/nginx bf5952930446: Pull complete cb9a6de05e5a: Pull complete 9513ea0afb93: Pull complete b49ea07d2e93: Pull complete a5e4a503d449: Pull complete Digest: sha256:b0ad43f7ee5edbc0effbc14645ae7055e21bc1973aee5150745632a24a752661 Status: Downloaded newer image for nginx:latest
here i pulled nginx docker image, by default it will pull the latest tag.
Create Docker Container
to create docker container from the pulled docker images, we use docker run command.
docker run -itd <image-name>
$ docker run -itd nginx 518d99a10b22e52936f1d728b12b480ad7a9fc5643ceb651db07ff27566189d1
here 518d99a10b22e52936f1d728b12b480ad7a9fc5643ceb651db07ff27566189d1 is container ID.
List the Running Containers
just now we have created the container, to list only the running containers we use docker ps command. this command will list all the running docker images. this command will not shows us the stopped containers.
$ docker ps CONTAINERID IMAGE COMMAND CREATED STATUS PORTS NAMES 518d99a10b22 nginx "/docker-entrypoint.…" 3 minutes ago Up 3 minutes 80/tcp gifted_swartz
List ALL the Containers
to list all the running and stopped containers we use docker ps -a command.
docker ps -a
$ docker ps -a CONTAINER ID IMAGE COMMAND CREATED STATUS PORTS NAMES 518d99a10b22 nginx "/docker-entrypoint.…" 10 minutes ago Up 10 minutes 80/tcp gifted_swartz 966f927cd4e9 redis "docker-entrypoint.s…" 46 seconds ago Exited (0) 39 seconds ago tereshkova
here you can see redis container status, it is stopped. if you use docker ps command it will show about only running docker containers.
Enter into Docker container shell
to enter into docker container shell or to access the docker container we use docker exec command.
docker exec -it <container_id> bash
$ docker exec -it 518d99a10b22 bash root@518d99a10b22:/#
Stop Docker container
To stop docker container we use docker stop command.
docker stop <container_id>
$ docker stop 518d99a10b22 518d99a10b22 $
Start the docker container
to start the stopped container we use docker start command.
docker start <container_id>
$ docker start 518d99a10b22 518d99a10b22
Stop the container forcefully
to stop the docker container forcefully we use docker kill command this command will stop the container immediately. some times containers will not stop using stop command and it will take more time to stop, at that conditions we can docker kill command to stop the docker container.
$ docker kill 518d99a10b22 518d99a10b22 $
exit from containner cnrel+p+Q