"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
Check if the system is up-to-date using the following command:
sudo apt-get update
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
Before testing Docker, check the version installed using the following command:
docker --version
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
To check if the docker service is running
service docker status
To start or stop the docker service
service docker start/stop
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 containersdocker ps -a
- To list all containers including stopped/exited containersdocker stop <container>
- To stop a running containerdocker start <container>
- To start a stopped containerdocker rm <container>
- To remove the stopped container.docker rmi <image>
- To remove the imagedocker 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.