Setup Docker & Docker Compose on Ubuntu
In this blog post, We will understand docker and how to install docker and docker-compose on Ubuntu operating system.
Table of Contents
● What is Docker?
● What is Docker Containers?
● Features of Docker
● What is Docker Compose?
● Docker Engine
● Installing Docker Packages on Ubuntu OS
● Installing Docker Compose on Ubuntu OS
What is Docker?
Docker is an open-source platform for developing, shipping, and running applications.
Docker uses Containers on the Host operating system to run the applications.
Containers ensure that the application runs on any environment such as Dev, UAT, Production.
We can significantly reduce the delay between writing the codes and running applications in the Production environment.
Using docker, We can segregate the applications from the infrastructure. By doing so we can quickly deliver the applications.
Docker has components such as Docker client, Docker server, Docker Hub, Docker Compose, etc.
What is Docker Containers?
A container is a standard unit of software that packages up code and all its dependencies so the application runs quickly and reliably from one computing environment to another.
A Docker container image 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 in the case of Docker containers — images become containers when they run on Docker Engine.
Docker containers that run on Docker Engine:
● Standard: Docker created the industry standard for containers, so they could be portable anywhere
● Lightweight: Containers share the machine’s OS system kernel and therefore do not require an OS per application, driving higher server efficiencies and reducing server and licensing costs
● Secure: Applications are safer in containers and Docker provides the strongest default isolation capabilities in the industry
Features of Docker
Here is the list of some of the great features of Docker,
● Faster and easier configuration
● Swarm
● Application isolation
● Increase in productivity
● Better Software Delivery
● Routing Mesh
● Security Management
● Rapid scaling of Systems
● Software-defined networking
What is Docker Compose?
Docker-compose is a tool for defining and running multi-container docker applications.
We will use a YAML file to configure definitions for the applications and services. Once the compose file is ready, We can easily deploy and manage docker applications using a single file.
Docker-compose is basically a three-step process:
● Define the application’s environment in Dockerfile
● Define the services that will create an application in the docker-compose.yml file so that they can run together in isolated environments.
● Then run docker-compose up to start and run the applications.
Docker-compose can perform the following actions:
● Start, Stop and Rebuild the services
● Check the status of the running applications
● Stream log out of the running services
● Running a one-off command on a service
Example of Docker composes file.
version: ‘3’ services:
web:
image: Nginx DB:
image: MySQL ports:
- “3306:3306”
environment:
- MYSQL_ROOT_PASSWORD=securepassword
- MYSQL_USER=someuser
- MYSQL_PASSWORD=securepassword1
- MYSQL_DATABASE=sampledb
You May Also Like: How to Create SQL Server Database in AWS RDS
What is Docker Engine?
Docker Engine is a Client-server application that has 3 major components.
● A docker daemon (the docker command), which is a long-running program, Also referred to as a service
● A REST API specifies the interface that programs can use to communicate with daemons and run commands against them.
● docker command, a command-line tool, called docker client.
Installing Docker Packages on Ubuntu
Let us go ahead and install the stable version of Docker on the Ubuntu system using the commands provided below.
Run the below command, to update the packages lists for upgrading the packages and also the new packages that were added to the repository.
sudo apt-get -qqy update
And then install the below packages on the system to allow apt to use repositories over HTTPS.
sudo apt-get -y install apt-transport-HTTPS ca-certificates curl software-properties-common wget pwgen
curl -fsSL https://download.docker.com/linux/ubuntu/gpg | sudo apt-key add -
Using the below command, We can add the stable version of the Docker repository.
sudo add-apt-repository “deb [arch=amd64] https://download.docker.com/linux/ubuntu $(lsb_release -cs) stable”
Before installing the latest stable version of Docker on Ubuntu systems,
First, we need to remove the older version of docker installed on the system, Using the below command.
sudo apt-get remove docker docker-engine docker.io contained runs
It will delete the above-listed packages and their dependencies.
Let's Install the docker engine from the stable repo added to the system.
sudo apt-get update && sudo apt-get -y install docker-ce
Once the packages are installed, start the docker service and check the status of the Docker engine.
The installation of the docker packages will automatically set up the system unit file to manage the docker daemon.
sudo systemctl start docker
sudo systemctl status docker
We can check the version of the Docker engine installed.
sudo docker — version
Installing Specific Version of Docker Engine
If you wish to install the specific version of the docker engine from the repository.
First list the available versions in the repo and then run them then we will install the specific version of docker.
sudo apt-cache madison docker-ce
You can find the lists of available versions of docker.
To install the specific version, You can select the version string from the second column.
For example 5:19.03.3~3–0~ubuntu-bionic
Let's install the above-mentioned version using the below command.
sudo apt-get install docker-ce=5:19.03.3~3–0~ubuntu-bionic docker-ce-cli=5:19.03.3~3–0~ubuntu-bionic containerd.io
If you are installing a custom version of docker and If the docker is already present on the system, The above commands with either Upgrade or Downgrade the docker version depending on the currently installed version of Docker.
Once installation is completed, Check the docker service and enable it to run on system boot.
Installing Docker Compose
Docker-compose relies on the Docker engine, So make sure the docker engine is installed on the system, either on local or remote.
Lets install the docker compose on the Ubuntu server.
sudo curl -L https://github.com/docker/compose/releases/download/1.22.0/docke r-compose-$(uname -s)-$(uname -m) -o
/usr/local/bin/docker-compose
Making the docker-compose binary file executable.
sudo chmod +x /usr/local/bin/docker-compose
You can check the version of docker-compose using the below command.
sudo docker-compose — version
We have successfully installed Docker Engine and Docker Compose on the Ubuntu Operating system.