What is Docker?
Docker is a platform that uses containers to create, manage and use applications.
And what is a container? It can be considered as a package of an application, containing all the necessary dependencies and libraries needed to run the application and can be shipped as one package since they are isolated. This process is called containerization. Docker makes it possible to deploy containers in one or a cluster of Linux machines, where the containers shares resources with the host computer, unlike a virtual machine that get dedicated resources from the host. Containers are therefore preferred to virtual machines since they are light-weight and easy to deploy.
Where is docker useful?
Developers and system administrator mostly use containers to enable them isolate code and applications. It makes it easier for them to make changes to a program. Many containers can run on a single Linux computer reducing the number of systems needed and lowering overhead.
How then can I install Docker CE in Linux Mint 20?
Docker is presented as a Community Edition (CE) and Enterprise Edition (EE). This guide gives a step-by-step guide on how to install ad use docker CE in Linux Mint 20.
Update your system
First ensure that your system packages are updated
sudo apt-get update
Install Docker dependencies and add Docker official key
APT does not use HTTPS and it is crucial to install the packages and dependencies that will enable it to use a repository through https
sudo apt-get install apt-transport-https ca-certificates curl gnupg-agent software-properties-common
Next add Docker official key which is important in enabling Docker repo.
curl -fsSL https://download.docker.com/linux/ubuntu/gpg | sudo apt-key add -
Adding Docker repository
Next thing is to add Docker repository to Linux Mint. The variable ‘$ (. /etc/os-release; echo “$ubuntu-codename”)’ ensures that you are using the right distribution of your Linux Mint
sudo add-apt-repository "deb [arch=amd64] https://download.docker.com/linux/ubuntu $(. /etc/os-release; echo "$UBUNTU_CODENAME") stable"
Update your system again
sudo apt-get update
Install Docker CE on Linux Mint 20
Run the below command to install the latest version of Docker CE
sudo apt-get -y install docker-ce
Once installed a docker group will be created. Add your user to the group who will be running docker commands.
sudo usermod -aG docker $USER
Verify Docker Installation
Show docker version
sudo docker --version
The output should show docker version and build
Some Docker commands
Docker is used with syntax as shown below:
$ docker [options] [command] [arguments]
To check options to be used with docker, run:
$ docker help
What is Docker hub
Docker hub is a registry of docker images that can easily be pulled to run containers. An image is like a container snapshot, which when started creates a container. An image is downloaded from the hub with ‘pull’ command and run with ‘run’ command.
Example: How to run nginx with docker
Use the ‘pull’ command to get nginx image from docker hub
sudo docker pull nginx
The output should be as shown below:
You can check the existing images by running the command below:
sudo docker images
The images will be listed as shown
To run nginx we need to expose the container port to network port, in this case port 80
sudo docker run --name docker-nginx -p 80:80 nginx
To verify that nginx is running, open your browser and enter http://localhost. The output should be nginx welcome page
You can check all the running containers by issuing the command below. Adding -a at the end of the command displays all running containers
sudo docker ps sudo docker ps -a
To stop a container, take the container ID from the command above and use it to stop as below:
sudo docker stop <container-ID>
This has been an informative step-by-step guide on how to install and use docker CE in Linux Mint 20. I hope it has been useful to you.
Click the links below to check on our other useful guides for your Linux installations.