Day 16 of #90DaysOfDevOps

Day 16 of #90DaysOfDevOps

"If you ever encounter developers saying, 'It works on my machine,' then introduce them to Docker."

What is Docker?

Docker is an open platform for developing, shipping, and running applications. Docker helps developers build, share, run, and verify applications anywhere without tedious environment configuration or management.

What is Image?

Docker Image is an executable package of software that includes everything needed to run an application. This image informs how a container should instantiate, determining which software components will run and how.

In simple words, docker images are the read only binary templates used to create docker containers. Docker image is a single file with all the dependencies and configuration required to run a program.

What is container?

Docker Container is a virtual environment that bundles application code with all the dependencies required to run the application. The application runs quickly and reliably from one computing environment to another.

Container is a running instance of the image.


Docker installation on Ubuntu :

Let's first install docker on our Ubuntu machine

  1. Check if the system is up-to-date using the following command:

    sudo apt-get update

  2. Install Docker using the following command:

    sudo apt install docker.io

    You’ll then get a prompt asking you to choose between y/n - choose y

  3. Before testing Docker, check the version installed using the following command:

    docker --version

  4. Executing the Docker Command Without Sudo

First, establish the Docker Group:

Making the docker group is the initial step. Run a particular phrase in a terminal window if it doesn't already exist:

sudo groupadd docker

The next thing to do must add the individual to the group for Docker;

execute the command line below to do so:

sudo usermod -aG docker $USER

Third step: restart the computer:

Reboot the computer now to view the modifications you made.

sudo reboot

  1. To check if the docker service is running

    service docker status

  2. To start or stop the docker service

    service docker start/stop

  3. Start Docker Service Automatically On System Boot

    systemctl enable docker.service


Docker basic commands :

Let's now look into some basic docker commands to get started with docker.

  • docker images - Lists the downloaded images on docker host.

  • docker search <image> - To search images on docker hub.

  • docker pull <image> - To download images from docker hub.

  • docker run <image> - To run a container from a image.

  • docker ps - To list all running containers

    docker ps -a - To list all containers including stopped/exited containers

  • docker stop <container> - To stop a running container

  • docker start <container> - To start a stopped container

  • docker rm <container> - To remove the stopped container.

  • docker rmi <image> - To remove the image

  • docker attach <container> - To access the container in interactive mode, it will connect to the standard input/output of the main process inside the container.

  • docker exec -it <container> - To access the container in interactive mode, it will create a new process in the containers environment.

  • docker inspect <container> - Display detailed information on one or more containers.

  • docker port Command to list the port mappings for a container.

  • docker stats Command to view resource usage statistics for one or more containers.

  • docker top Command to view the processes running inside a container.

  • docker save Command to save an image to a tar archive.

  • docker load Command to load an image from a tar archive.