Swipe left or right to navigate to next or previous post

Comprehensive list on docker commands

25 Dec 2022 . category: Docker . Comments
#Server #Docker

Ultimate guide on docker - Tapan BK

Docker is the service that manages the container. It is based on the philosophy of develop, ship and run anywhere. The docker helps developers to easily develop applications, ship the applications into the containers that can be deployed everywhere.

Pros of Docker

  • Reduce the size of development by providing a smaller footprint of the Operating system through containers.
  • Helps developers, QA and operations to work seamlessly across various platforms.
  • Lightweight
  • Scalable
  • Dockers can be deployed anywhere

Cons of Docker

  • There are a ton of feature requests are under progress, like container self-registration, and self-inspects, copying files from the host to the container, and many more
  • Containers don’t run at bare-metal speeds.
  • Docker less attractive in some highly heterogeneous environments which are composed of both Windows and Linux servers
  • For applications that require rich interfaces, Docker is not a good solution
  • Docker creates new security challenges like the difficulty of monitoring multiple moving pieces within a large-scale, dynamic Docker environment.

Commands related to docker images

Pull the docker images

    sudo docker pull hello-world

This will pull the hello-world image from remote docker hub

Run the docker image

    docker run hello-world

This command is used to create an instance of the image which is also called a container

Run the docker image in interactive mode

    docker run -it hello-world /bin/bash

/bin/bash is used to run the bash shell once hello-world is up and running.

List docker images

    docker images

This command is used to display all the images currently installed in the system

It will display the following information

  • TAG − This is used to logically tag images.
  • Image ID − This is used to uniquely identify the image.
  • Created − The number of days since the image was created.
  • Virtual Size − The size of the image.

Download the docker image using the run command

    docker run hello-world

This command will download the hello-world image if the image is not present on the system and run the image as container

Removing docker images

    docker rmi imageId

This command will remove the image with the mentioned imageId

Show the docker images Id only

    sudo docker images -q

This command will only show the image id of all the images in the system

See the details of the docker or container

    sudo docker inspect hello-world

Commands related to docker container

List all the running containers on the machine

    docker ps

List all the containers on the machine

    docker ps -a

Stop the docker container

    sudo docker stop containerId

This command will stop the container with the mentioned containerId

Remove/Delete the docker container

    sudo docker rm  containerId

This command will delete/remove the container with the mentioned containerId

Status of the docker container

    sudo docker stats containerId

This command will provide CPU and memory utilization of the Container

Kill the docker container

    sudo docker kill containerId

This command will kill the process running on the Container

Commands related to docker daemon

Stop the docker daemon

    sudo service docker stop

This command is used to stop the Docker daemon process.

Start the docker daemon

    sudo service docker start

This command is used to start the Docker daemon process.

Commands related to docker build

build the docker image

    docker build  -t ImageName:TagName dir

This method allows the users to build own Docker images.

Options

  • -t − is to mention a tag to the image
  • ImageName − This is the name you want to give to your image.
  • TagName − This is the tag you want to give to your image.
  • Dir − The directory where the Docker File is present.

Example:

    sudo docker build –t myDockerImage:0.1 .

Here, myDockerImage is the image name and 0.1 is the tag number. The '.' at the end of the commands signify the present working directory.

Pull the docker image

    sudo docker pull hello-world

This command is used to pull the hello-world from the remote docker repo.

Tag the docker image

    docker tag imageID RepositoryName

This command allows to tag an image to mentioned repo

Example

    sudo docker tag ab0c1d3744dd hello-world:1.0

Push the docker image to remote repo

    sudo docker push RepositoryName

This command allows one to push images to the Docker Hub.

Example

    sudo docker push hello-world:1.0

Tapan B.K. | Full Stack Software Engineer

Tapan B.K. is Full Stack Software Engineer. In his spare time, Tapan likes to watch movies, visit new places.