Essential Docker CLI Commands Cheat Sheet: Images, Containers, Compose & More

Introduction to Docker CLI

docker cli commands

The Docker CLI 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.

Docker Image Management Commands

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.

1. Pulling Docker Images

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

2. Listing Docker Images

Once an image is pulled from the registry into a local environment we need to see what all images are existing locally to display all images we use docker cli 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

3. Building Docker Images

Docker build command is uses to create docker images from Docker file. It can be local or remote.

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

Docker Container Management Commands

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

5. Running Docker Containers

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

Detached Mode (-d)

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

Interactive Mode (-it)

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

6. Executing Commands in Running Containers

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

7. Listing Running Containers

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

8. Inspecting Docker Containers

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

9. Stopping and Restarting Containers

Stop a running container:

Restart a container:

10. Viewing Container Logs

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

Dockerfile Overview

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.

What is Docker Compose?

Key Features:

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

Docker Compose V2 Highlights:

  • 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

Conclusion

Docker CLI commands help you to manage and build you applications with docker and containers. There are multiple ways by which you can minimize the complexity such as compose & Google Jib.


Comments

2 responses to “Essential Docker CLI Commands Cheat Sheet: Images, Containers, Compose & More”

  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 *