Table of Contents
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
Pulling latest images from docker hub
# docker pull python OR docker image pull python
# docker pull openjdk OR docker image pull openjdk
# docker pull mysql OR docker image pull mysql
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
Listing all images
# docker images
Listing all images fom a repository
# docker images python
# docker images mysql
# docker images java
Filtering images since a particular image
# docker images --filter "label=tag=latest"
Filtering and formatiing in a fiven format
#docker images --format "table {{.Repository}}\t{{.Tag}}"
Docker Build
Docker build command is ues to create docker images from dockerfile. dockerfile can be local or remote.
Building with docker file in the same path
# docker build .
Building with docker from a path
# docker build ./$path to dockerfile$
Building from a URL
# docker build github.com/test/dockerfile
Specifying a file other than dockerfile for build
# docker build -f Dockerfile.debug
Docker Search
Docker Search command will search images from docker hub or given registry.
Searching Docker image by name of DB2
# docker search db2
Searching Docker images by name of python or contains python
# docker search python
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.
Running a Python Image
# docker run python
Docker Run – Detached Mode
The (-d) detach flag will start a container as a background process that doesn’t occupy your terminal.
Running Docker image in detached mode
# docker run -d python
Running Docker Image in a detached mode with Image Name
# docker run --name pyContainer -d python
Docker Run – Interactive Mode
The (-it) flag will start the container and open its STDIN(shell) for running commands.
Running python image in interactive Mode
# docker run -it python
Running openjdk image in interactive mode with Jshell
#docker run -it openjdk
Docker Container Exec
Docker exec command will execute a given command inside a running container.
The command specified will run while container is running.
Open Shell terminal inside thecontainer and listing all files at root directory
# docker exec -it pyCont1 sh -c "ls -lrt"
Executing Java commands inside a container via a Jshell
# docker exec -it javaCont jshell
# docker exec -it mysql bash
Docker Container Ls
Docker Container Ls OR Docker ps command will list all running containers.
List all Running Containers
# docker ps
List the latest running containers
# docker ps -l
List the last 2 containers
# docker ps -n 2
Listing Data with filtered columns
# docker ps --format "table {{.Names}}\t{{.Image}}"
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.
Inspecting a Container
# docker inspect <Container Name>
# docker inspect pyCont
Docker Container Stop
Docker stop will stop one or more running containers.
Stopping given container
# docker stop <Container Name>
# docker stop pyCont
Docker Container Restart
Docker Restart will one or more containers.
Restarting given Container
# docker restart <Container Name>
# docker restart pycont
Docker Container Logs
Docker Container logs will fetch the logs present at the time of execution.
docker logs <Container Name>
docker logs pyCont
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
Leave a Reply to Why we need Docker(Docker Overview)? %sitename Cancel reply