Docker CLI commands

Docker Base command(Docker CLI Commands)

The Docker CLI base commands is docker. Once docker is set up on your machine you will be able to access multiple subcommands with the help of the docker keyword.
There are numerous docker cli commands available for a different purposes but here we are going to look at some basic commands for building, pushing, and pulling images from the docker hub and starting, and stopping containers.

Images

Docker images are build, pulled pushed and deleted with the help of various commands we will see some of the examples below that will help to do so.

Docker Pull

The Docker Image pull command is used to pull an image from the registry(docker hub).
In an enterprise you may need to configure the docker daemon’s proxy setting for details refer here.
Refer Some samples below

Docker Images

Once an image is pulled from the registry into a local environment we need to see what all images are exisiting locally to display all images we user docker image commands. Docker Images will show all the top-level images and tags and their size.

docker image ls OR docker image list OR docker images

Docker Build

Docker build command is ues to create docker images from dockerfile. dockerfile can be local or remote.

Docker Search command will search images from docker hub or given registry.

Containers

Containers are created by running docker images. Containers can be created stopped removed and restarted on the basis of given requirement.
We are going to look at some basic commands for containers

Docker Run

The docker run command runs a new container with the required image, also pulling the image from the registry.

Docker Run – Detached Mode

The (-d) detach flag will start a container as a background process that doesn’t occupy your terminal.

Docker Run – Interactive Mode

The (-it) flag will start the container and open its STDIN(shell) for running commands.

Docker Container Exec

Docker exec command will execute a given command inside a running container.
The command specified will run while container is running.

Docker Container Ls

Docker Container Ls OR Docker ps command will list all running containers.

Docker Inspect

The Docker Inspect command will run low-level information on docker objects(Container).
By default it will return all information in a JSON array.

Docker Container Stop

Docker stop will stop one or more running containers.

Docker Container Restart

Docker Restart will one or more containers.

Docker Container Logs

Docker Container logs will fetch the logs present at the time of execution.

Docker File

What is a Docker File ?

Docker is a text file used to build an image. It contains all the command that are required to create a new image from a given base image.

Docker Compose

  • Define and run multi -container applications
  • define Uding YAML files
  • Run using the docker CLI with compose plugin
  • Docker compose
  • Compose Specs

Compose V2

  • General availability of Compose V2 started at DockerCon Live 2022
  • in V1(docker-compose) and in V2 is (docker compose)
  • Installed with docker desktop
  • Written in Go
    docker compose is written in Python
  • In summary, it’s simply a faster version of the good old docker compose tool that is shipped as a plugin instead of a Python app


Comments

2 responses to “Docker CLI commands”

  1. […] thedevopsguy.co.in in Blog Next Post […]

  2. […] thedevopsguy.co.in in Blog Next Post Prev Post […]

Leave a Reply to Why we need Docker(Docker Overview)? %sitename Cancel reply

Your email address will not be published. Required fields are marked *