What is Docker?
What is a Docker Hub?
Docker Hub is a Container Image Library or App Containerization to create, manage and deliver containerized application at ease. It is a service provider by Docker to pull and push container images.
Docker Hub Container Image Library is a open source projects, independent software vendors for building, managing and distributing.
Create an account or Login to your Docker Hub @ https://hub.docker.com/
Docker Container:
Docker Container Image: It is a package with all the dependencies and information required to create a container.
- Dependencies include frameworks and the deployment and execution configuration that a container runtime uses.
- Usually, an image derives from multiple base images that are layers stacked on top of each other to form the container's file system.
- An image is immutable once it has been created.
Docker Build: Action of building a container image based on the information and context provided in the Dockerfile.
Docker Pull: Process of downloading a container image from a container registry.
Docker Push: Process of uploading a container image to a container registry.
Dockerfile: Dockerfiles enable you to create your own images. It is like a batch script. It refers to a text file that contains set of instructions on how to build a Docker image. The first line identifies the base image. The rest of the file includes the build actions.
Docker Commands Cheat Sheet
Command | Description |
---|---|
docker attach | Attach local standard input, output, and error streams to a running container |
docker build | Build an image from a Dockerfile |
docker commit | Create a new image from a container’s changes |
docker cp | Copy files/folders between a container and the local filesystem |
docker create | Create a new container |
docker diff | Inspect changes to files or directories on a container's filesystem |
docker events | Get real-time events from the server |
docker exec | Run a command in a running container |
docker export | Export a container’s filesystem as a tar archive |
docker history | Show the history of an image |
docker images | List images |
docker import | Import the contents from a tarball to create a filesystem image |
docker info | Display system-wide information |
docker inspect | Return low-level information on Docker objects |
docker kill | Kill one or more running containers |
docker load | Load an image from a tar archive or STDIN |
docker login | Log in to a Docker registry |
docker logout | Log out from a Docker registry |
docker logs | Fetch the logs of a container |
docker network | Manage Docker networks |
docker node | Manage Swarm nodes |
docker pause | Pause all processes within one or more containers |
docker plugin | Manage plugins |
docker port | List port mappings or a specific mapping for the container |
docker ps | List containers |
docker pull | Pull an image or a repository from a registry |
docker push | Push an image or a repository to a registry |
docker rename | Rename a container |
docker restart | Restart one or more containers |
docker rm | Remove one or more containers |
docker rmi | Remove one or more images |
docker run | Run a command in a new container |
docker save | Save one or more images to a tar archive (streamed to STDOUT by default) |
docker search | Search the Docker Hub for images |
docker service | Manage Docker services |
docker start | Start one or more stopped containers |
docker stats | Display a live stream of container(s) resource usage statistics |
docker stop | Stop one or more running containers |
docker swarm | Manage Swarm |
docker tag | Tag an image to a repository |
docker top | Display the running processes of a container |
docker unpause | Unpause all processes within one or more containers |
docker update | Update configuration of one or more containers |
docker version | Show the Docker version information |
docker volume | Manage Docker volumes |
docker wait | Block until one or more containers stop, then print their exit codes |
These are all the Docker commands available for managing and working with containers, images, and other Docker objects. By using these commands efficiently, you can streamline your Docker workflow and be more productive in your development work.
Steps to Install Docker on Linux:
Install Docker:
Connect to Linux Server and Install docker by following the steps below:
Update the package index by by running the command 'sudo yum -y update'
sudo yum -y update
Install the latest version of Docker by running the command 'sudo yum install -y docker'
sudo yum install -y docker
Verify Docker Installation:
To verify that Docker is installed and running correctly on a Linux server by running the command docker --version in the terminal.
docker
or
docker -v
or
docker --version
This command returns the information about both the version of the Docker client and the version of the Docker server that is running on your machine.
Docker version refers to the release number of the Docker software. It typically consists of three parts: major version, minor version, and patch version. For example, "Docker version 19.03.13" refers to major version 19, minor version 03, and patch version 13.
Each new version of Docker may include new features, bug fixes, and performance improvements. It is important to keep your Docker version up to date to ensure that you have the latest security fixes and features.
Start Docker Service:
Once can start the docker service by running the following command below.
sudo service docker start
To run the Docker command without sudo, add the current user to the docker group
sudo usermod -a -G docker "user"
Docker Info:
One can check the detailed information on the running/stopped containers by running the following command in the terminal.
docker info
Download Docker Image:
Docker images can be downloaded from Docker Hub using docker commands. Lets pull an image from docker hub using pull command.
Download a image from docker hub - Ngnix Official Docker Hub Image
Syntax : docker pull <<image name>>
use the following command to run ngnix image.
docker pull nginx
Reference link: Nginx - Official Image | Docker Hub
Docker Run:
Run an image in docker container using docker run command
syntax: docker run <<image name>>
cmd: docker run --name nginxservice -d nginx
--name: to specify a name for the running service. In this example, it is nginxservice
-d : to run the service in the background.
Check Docker Images:
You can verify the downloaded docker images using the following command
docker images
View all the commands that were run with an image via a container.
syntax: docker history <<image name>>
cmd: docker history nginx
Docker PS:
use the following command to get the list of running containers (Health Check).
docker ps
The -a option can be added to the command to show all containers, not just running ones. Use the following command to get the list of all containers.
docker ps -a
Remove Docker Image:
One can remove an image using the docker rmi command:
Syntax: docker rmi <image name>
cmd: docker rmi nginx
This command will remove the specified image from the system. If the image is in use by a running container, you will need to stop and remove the container first before removing the image.
Remove Multiple Docker Image:
One can remove multiple images at once using the docker rmi command:
docker rmi $(docker images -q)
Docker Stop:
sudo service docker stop
Uninstall Docker:
uninstall docker
Remove Docker:
use the following command to remove docker completely from your system.
sudo yum remove docker
Docker Container Commands:
Docker Commands (Container 1):
Kill the processes in a running container -
Start the same container -
Stop the running container -
Delete a container -
To remove all stopped containers -
Docker Commands (Container 2):
Export a container -
Import a container -
Diagnose Run Issues -
Related Articles:
👉 Install Azure PowerShell and Azure AD PowerShell
👉 How to Find Azure VM Username and Password