Useful commands of Docker

For more detail or details of client and server Engine

$ docker version

For lesser docker version details

$ docker –version

To create a container

$ docker run -d –name ubuntujavacont  myfuturrhub/ubuntu:

To get docker Logs

$ docker logs –details <container>namejira

For Registry logs (if registry is configured)

$ docker logs registry

To login to docker

$ docker login

docker images

$ docker ps 

To pull docker image

$ docker pull docker.io/<user_name><repository_name>:Tag

To copy image with different tag name

$ docker tag docker.io/<user_name><repository_name>:Tag.    docker.io/<user_name><repository_name>:New_Tag

To push docker container

$ docker push docker.io/<user_name>/<repository_name>:Tag

To let the container up and running

$ docker run -itd ubuntu

itd : Interactive Terminal detached mode

To Stop a container

$ docker stop <Container_ID>

To Start a container

$ docker start <Container_ID>

To restart a container

$ docker restart <Container_ID>

To Lists port mapping of container

docker port <container>

To suspends all processes in container 

docker pause <container>

To unsuspends all processes in container 

docker unpause <container>

To get in to container in attached mode

$ docker run -it buntu

To exit and close container

$ exit

(or)

$ ctrl+d

To exit container with out closing container

$ ctrl+p+q 

To attach or get in to a container

$ docker attach <container_id>

To remove containers (use this responsibly)

$ docker rm <container_id>

To remove docker images

$ docker rmi <image_id>

To Copy files on container to docker host

$ docker cp copiyingfile:/file.txt .

To copy files on docker host to container

$ docker cp file2.txt <container_name>:/<dest_path>

To check history of image

$ docker history <image>:<tag>

To pull docker image

$ docker pull repository_name:tag

To build Image from docker file

$ docker build -t <hub.docker_user_name>/image:tag_nae

Example :

$docker build -t myfuturehub/ubuntu:dockerfile .

To check docker network

$ docker network ls

To add a containter to a network 

$ docker run -d –net=my_bridge –name db training/postgres

To attach existing container to a network

$ docker network connect my_bridge web

To delete all containers in one go -Note : Do Not Run this command in Production

$ docker rm $(docker ps -a -q)

To Kill a running container (use this command responsibly)

$ docker kill

Adding user to Docker Group

$ sudo usermod -aG docker $USER

Docker user file will be updated at /var/run/docker.sock

Pushing and Pulling to and from Docker Hub (To get other public images to docker hub)

1st step : Tag the public repository

$ docker tag <Image_id> dockerusername/repositoryname:v0.1

2nd step : push the image

$ docker push dockerusername/repositoryname

To connect to a container

$ Docker exec <cotain_id>

Advantage of docker exec is with out even entering into container, we can execute commands 

$ docker exec <container_id> ls

To come out of a container

Cntrl P Q

Docker inspect gives all the details of container :

  • Details of cmd/s used to launch the container
  • Details of the image used
  • Details of Host Ports
  • Details of Networks (Network type ex : bridge, IPAddress etc)
  • Environment Variables in the container
  • State of the container (Status, Error, StartedAt, FinshedAt etc)

Below command is to to see the CPU, Memory utilization of container

$ docker stats

To see container size, created date, status, ports etc

$ docker ps -s

P : Container size is typically the size of the image.

To permanently remove the container

$ docker rm

To see utilization of the system

$ docker system df

To delete all stopped containers

$ docker container prune

To see the activity of the container

$ docker logs <container_id>

To see live streaming 

$ docker logs -f <container_id>

Other Basic Docker Commands :

To list live containers 

$ docker ps

List all containers

$ docker ps -a

To Retrieves docker configuration 

$ docker info 

If you have any questions, you can whatsapp using WA chat icon on right corner of this website, our Sr.Advisor will be happy to help you.

Leave a Comment

MFH DevOps Consultation Services

Add Few lines about the company here

Contact

MFH Devops Consulation
#4-72-1/1. 1st Floor, Beach Road Lawson’s Bay Colony, Near Shanti Ashram, Opp. Bharat Petroleum, Visakhapatnam, Andhra Pradesh – 530017