DEV Community

AyushDabhi
AyushDabhi

Posted on

Docker Commands

docker --version

Used to check your docker version

docker --version
Enter fullscreen mode Exit fullscreen mode

docker pull

Which pulls the image from the repository to your local environment

docker pull redis # It will pull redis image
Enter fullscreen mode Exit fullscreen mode

Image description

docker ps

It gives running container details.

docker ps
Enter fullscreen mode Exit fullscreen mode

Image description

docker start

Restart a stopped container.

docker start 7aaaa6322b5f # write container id or name
#OR
docker start sad_hugle
Enter fullscreen mode Exit fullscreen mode

Image description

Note: CONTAINER ID and NAME is randomly generated. Check your CONTAINER ID and NAME by running the docker ps command.

docker stop

Use to stop running container

docker stop CONTAINER_ID 
# OR
docker stop NAMES
Enter fullscreen mode Exit fullscreen mode

Image description

docker run

Which combines pull and start, pulls the image if it's not locally available and then starts it right away.

docker run node #It will pull and start the node container
Enter fullscreen mode Exit fullscreen mode

Image description

docker run -d

Run the container in detached mode. This means that the container will run in the background and the console output will not be shown in the current terminal session.

docker run -d redis
Enter fullscreen mode Exit fullscreen mode

Image description

docker ps -a

Which gives you all the containers no matter if they're running currently or not.

docker ps -a
Enter fullscreen mode Exit fullscreen mode

Image description

docker run -p6000:6794

Allows you to bind the port of your host to the container

-p => port

6000 => The port of Host

6794 => The port of the container

Image description

docker images

Which gives you all the images that you have locally available.

docker images
Enter fullscreen mode Exit fullscreen mode

Image description

docker rm

Remove a Container

docker rm CONTAINER_ID

#OR

docker rm NAME
Enter fullscreen mode Exit fullscreen mode

Image description

Note: You can't remove running container directly first stop the container using docker stop CONTAINER_ID

docker rmi

Remove images

docker rmi IMAGE_ID 

#OR

docker rmi IMAGE_NAME
Enter fullscreen mode Exit fullscreen mode
docker rmi -f IMAGE_ID  # -f means forced fully remove image

#OR

docker rmi -f IMAGE_NAME
Enter fullscreen mode Exit fullscreen mode

Note: Delete all dependent containers to remove the image

Image description

Thanks for reading !!

Top comments (0)