Docker  Commands

Docker Commands

ยท

2 min read

docker info

Displays system information

docker info

docker login

Log in to Docker Hub

docker login

docker --version

Used to check your docker version

docker --version

docker pull

Which pulls the image from the repository to your local environment

docker pull redis # It will pull redis image

docker ps

It gives running container details.

docker ps

docker start

Restart a stopped container.

docker start 7aaaa6322b5f # write container id or name
#OR
docker start sad_hugle

#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 the container

docker stop CONTAINER_ID 
# OR
docker stop NAMES

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

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

docker ps -a

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

docker ps -a

docker run -p6000:6794

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

-p => port

6000 => The port of Host ( External Port )

6794 => The port of the container ( Internal Port )

docker images

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

docker images

docker rm

Remove the container from memory.

docker rm CONTAINER_ID

#OR

docker rm NAME

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

docker rmi

Remove the image

docker rmi IMAGE_ID 

#OR

docker rmi IMAGE_NAME
docker rmi -f IMAGE_ID  # -f means forced fully remove image

#OR

docker rmi -f IMAGE_NAME

#Note: Delete all dependent containers to remove the image

Thanks for reading !!

Did you find this article valuable?

Support AyushDabhi by becoming a sponsor. Any amount is appreciated!

ย