Docker — Learning Simplified
What are container?
Consider container as packaged box having application code and its dependencies, which can run quickly and reliability on different OS environment. Code and dependencies when built as bundle form images which is a lightweight, standalone, executable package of software that includes everything needed to run an application: code, runtime, system tools, system libraries and settings. Container images become containers at runtime and run the same regardless of the infrastructure. Containers isolate software from its environment and ensure that it works uniformly despite differences for instance between development and staging.
How Container are diferent from VMs?
Why Docker?
Majorly use of docker came in existence to support below needs:
- Fast, consistent delivery of your applications(Developer write code locally and share with peer or push to testing environment. Once testing evidences are supportive image can be deployed in production)
- Responsive deployment and scaling — address compatibility and dependencies issues across laptop, desktop and OS
Docker is an open platform for developing, shipping, and running applications. Docker enables you to separate your applications from your infrastructure so you can deliver software quickly. With Docker, you can manage your infrastructure in the same ways you manage your applications. By taking advantage of Docker’s methodologies for shipping, testing, and deploying code quickly, you can significantly reduce the delay between writing code and running it in production.
Docker Engine
Docker Engine is a client-server application with these major components:
- A server which is a type of long-running program called a daemon process (the
dockerd
command). - A REST API which specifies interfaces that programs can use to talk to the daemon and instruct it what to do.
- A command line interface (CLI) client (the
docker
command).
The CLI uses the Docker REST API to control or interact with the Docker daemon through scripting or direct CLI commands. Many other Docker applications use the underlying API and CLI.
The daemon creates and manages Docker objects, such as images, containers, networks, and volumes.

Docker Architecture
Docker uses client server architecture. Client communicate to daemon, which does the work of building, running and distributing docker containers.

Docker Daemon: The Docker daemon (dockerd
) listens for Docker API requests and manages Docker objects such as images, containers, networks, and volumes. A daemon can also communicate with other daemons to manage Docker services.
Docker Client : The Docker client (docker
) is the primary way that many Docker users interact with Docker. When you use commands such as docker run
, the client sends these commands to dockerd
, which carries them out. The docker
command uses the Docker API. The Docker client can communicate with more than one daemon.
Docker Registeries : A Docker registry stores Docker images. Docker Hub is a public registry that anyone can use, and Docker is configured to look for images on Docker Hub by default. You can even run your own private registry.
Docker Objects
Images: An image is a read-only template with instructions for creating a Docker container
You might create your own images or you might only use those created by others and published in a registry. To build your own image, you create a Dockerfile with a simple syntax for defining the steps needed to create the image and run it. Each instruction in a Dockerfile creates a layer in the image. When you change the Dockerfile and rebuild the image, only those layers which have changed are rebuilt other reuse cache. This is part of what makes images so lightweight, small, and fast, when compared to other virtualization technologies.
DOCKERFILE contain command as “INSTRUCTION”+ “ARGUMENTS”
To build image one need to run below command in folder of Dockerfile
docker build . -t <user login>/<image_name>
<user login> is only required if its not public image
Container: A container is a runnable instance of an image. You can create, start, stop, move, or delete a container using the Docker API or CLI. A container is defined by its image as well as any configuration options you provide to it when you create or start it. When a container is removed, any changes to its state that are not stored in persistent storage disappear.
Docker Commands
docker pull nginx — This command is used to pull images from the docker repository
docker ps — This command is used to list the running containers
docker ps -a — This command is used to show all the running and exited containers
docker run -it -d -e APP_COLOR=blue nginx — This command is used to create a container from an image. -i stand for interactive -t stand for terminal -d stand for detach, -e stand for environment, -p stand for port, -v stand for volume to mount storage on local machine
docker start <container name space> — start a container
docker stop <container id> — This command stops a running container
docker images — list images available
docker rm <container id> — command to remove container
docker rmi nginx — command will remove images
docker commit <conatainer id> <username/imagename> -This command creates a new image of an edited container on the local system
docker exec <namespaces> cat /etc/hosts — This command is used to access the running container
docker attach <container id> — command to attach container id
docker push <username/image name> — This command is used to push an image to the docker hub repository
docker commit <conatainer id> <username/imagename> — This command creates a new image of an edited container on the local system
docker build . -t <path to docker file> — This command is used to build an image from a specified docker file
Docker run -p port on which to host:port on container image_name — command to map container to host port
Docker compose
Compose is a tool for defining and running multi-container Docker applications. With Compose, you use a YAML file to configure your application’s services. Then, with a single command, you create and start all the services from your configuration.

Reference: https://www.docker.com