Author: Romaan,
Last Updated: Jan. 5, 2025, 4:14 a.m.
Docker is an open source platform that provides a light weight virtual environment. By light weight environment, I mean, it is NOT a virtual environment like Oracle Virtual box or VMware player or VMware workstation but allows the application and its processes to run in a secluded environment without polluting user's environment with ease of portability.
Docker Terminology
Cgroups - Linux kernel feature that limits, accounts for, and isolates the resource usage of a collection of processes.
Container - A runtime instance of a docker image
Docker image - An ordered collection of root filesystem
Dockerfile - A text document that contains all the commands you would normally execute manually in order to build a Docker image.
Registry - A hosted service containing repositories of images which responds to the Registry API
Docker Installation
Assuming you have are using Ubuntu operating system, below are the steps to install Docker:
Once we have the docker installed, we can use the below commands to have a quick look:
Docker basic information
sudo docker info # For system wide information on docker
sudo docker version # For docker version
Docker images
sudo docker search [image name] # Search for image in repository
sudo docker pull [image name] #Download image
sudo docker images # List installed images
sudo docker commit [container ID] [image name] # Save the state of container
sudo docker rmi [image_name] # Delete the image
One can build her own docker image. In order to build one, create a file named "Dockerfile", mention all the configurations and execute the below command:
sudo docker build [tag_name] -f Dockerfile-dev
Docker container management
sudo docker run -i -t [image_name] [argument] # Creates a container, -t Allocate pseudo terminal, -i Keep STDIN open even if not attached
sudo docker run -d -P [image_name] [arguments] # -d starts container in the background and -P makes any required network ports inside our container to our host
sudo docker run -d -p number:number [image_name] [arguments] # -d starts container in background and -p makes the host port to container port
sudo docker inspect [container_name] # Shows the mounted volume information
Docker Compose
One can use docker commands to manage docker containers and images but may get tired typing the commands repeatedly, specially when there are multiple docker instances that needs to be created or destroyed during development or deployed. Docker compose is exactly for this purpose. It can be used to create multiple docker instances. The docker compose looks for docker-compose.yml file where the configurations for creating multiple docker instances are stored.
docker-compose up -d # Starts up all the docker containers specified in docker-compose file
docker-compose logs # Prints the logs from all the containers on to the terminal
docker-compose stop -t 1 # Stops all the containers defined by docker-compose
docker-compose rm # Remove all the containers from memory
A typicla docker-compose file with two images is shown below:
Comments: