About Docker
Docker is a platform that helps developers to build, test, and deploy applications quickly. It uses OS-level virtualization to package software into standardized units called containers. These containers include everything the software needs to run, such as libraries, code, system tools, and runtime. Docker containers are portable and can be moved to different servers or environments.
Technical Terms
- Images: Read-only templates that contain instructions for creating a container, including application code, libraries, tools, dependencies, and other files. Images are similar to snapshots in virtual machine (VM) environments.
- Container: Containers are self-contained units of software that package code and all its dependencies together. These containers include everything the software needs to run, such as libraries, code, system tools, and runtime.
Real-time example MySql Install with Docker
Docker images vs Docker containers
|
Docker image |
Docker container |
What? |
A reusable, shareable template for creating containers. |
A self-contained, running instance of the software. |
Created from |
software code, dependencies, libraries, and instructions defined in a Dockerfile. |
A Docker image. |
|
Composition |
Read-only layers. |
Read-only layers with an additional read-write layer on top. (ex: setting up environment variables) |
|
Mutability |
Immutable. If there are changes, you have to build a new file. |
Mutable; you can change it at runtime as required. |
When to use |
To store application configuration details as a template. |
To run the application. |
Docker CLI Command
Docker Hub
Login into Docker |
docker login -u <username> |
|
Publish an image to Docker Hub |
docker push <username>/<image_name> |
Search Hub for an image |
docker search <image_name> |
Pull an image from a Docker Hub |
docker pull <image_name> |
Docker Images
Build an Image from a Dockerfile |
docker build -t <image_name> |
Build an Image from a Dockerfile without the cache |
docker build -t <image_name>. –no-cache |
List local images |
docker images |
Delete an Image |
docker rmi <image_name> |
Remove all unused images |
docker image prune |
Docker Container
Create and run a container from an image with a custom name |
docker run --name <container_name> <image_name> |
Run a container with and publish a container’s port(s) to the host |
docker run -p <host_port>:<container_port> <image_name> |
Run a container in the background |
docker run -d <image_name> |
Start or stop an existing container |
docker start|stop <container_name> (or <container-id>) |
Remove a stopped container |
docker rm <container_name> |
Open a shell inside a running container |
docker exec -it <container_name> sh |
Fetch and follow the logs of a container |
docker logs -f <container_name> |
To inspect a running container |
docker inspect <container_name> (or <container_id>) |
To list currently running containers |
docker ps |
List all docker containers (running and stopped) |
docker ps –all |
View resource usage stats |
docker container stats |
Finally
This article provides a foundational understanding of Docker, covering its core concepts and terminology. In the next article, we'll dive deeper into practical implementation by creating a Dockerfile, building an image from it, and running the container local.
Notes for Create an account in Docker Hub.
- Create an account in Docker Hub (Docker Hub).
- Create a repository and respective things as follows in the images attached.
Download Docker Desktop
Thanks.