Steps to Run Docker Commands on Ubuntu 20.04 LTS

Hello Dear Readers, In this Blog we will discuss about how the docker works & How to create a image using docker? Docker is a free & open source containerization platform. Using docker commands, we can easily create a own images & push/pull the image.

There are some docker commands to run on ubuntu:

Step 1: Update the System.

apt-get update

Step 2: Install Docker on Ubuntu so click on link https://www.hackerxone.com/2021/06/20/how-install-docker-ubuntu-2004-lts/

  • Check the docker status.

systemctl status docker

Step 3: Docker Syntax & Examples:

  • To check docker version.

docker --version

  • Here is the command output.

  • To create a docker-image.

docker build -t image-name . (path of the dockerfile or . means dockerfile in current directory)

  • Here is the command output.

  • To list the docker file.

docker images

  • Here is the command output.

  • To pull the image.

docker pull <image name>

  • Here is the command output.

  • To run docker image.

docker run -it -d <image name>

  • To list the containers.

docker ps

  • Here is the command output.

  • To list running & existing containers.

docker ps -a

  • To login into running container.

docker exec -it <container id> bash

  • To stop the running container.

docker stop container-id

  • Here is the command output.

  • To kill one or more running containers.

docker kill container-id

  • To creates a new image of an edited container.

docker commit <conatainer id> <username/imagename>

  • Again run docker ps command.
  • Here is the command output.

  • To login into the docker hub repository.Then provide the username & password.

docker login

  • Here is the command output.

  • To push an image to the docker hub repository.

docker push <username/image name>

  • To delete a stopped container.

docker rm <container id>

  • To delete an image from local system storage.

docker rmi <image-id>

  • To provide a tag name.

docker tag <image-name> <newName>/<repoName>:<tagName>

  • To display docker history.

docker history image-name

  • To Copy files/folders between a container and the local filesystem.

Syntax:

docker cp [OPTIONS] CONTAINER:SRC_PATH DEST_PATH|-

Example:

docker cp foo.txt container-id:/foo.txt

  • To display system-wide information.

docker info

  • To display the logs of a container.

docker logs CONTAINER-ID

Leave a Reply