This article applies to both Debian 10 Buster and Ubuntu 20.04 Focal.
What is Docker?
Docker is a containerisation technology that allows containers to be built quickly on a server and run software without polluting the host, eliminating the need to install and configure various environments. The open source Docker community is dedicated to improving this type of technology and making it freely available for the benefit of all users.
What is Docker Compose?
Traditionally, ops would need to run docker run
to start various containers, and once there are too many containers, it is impossible to remember all the run parameters and commands at once, so we can use Docker Compose to solve this problem.
Docker Compose is a tool to help define and share multi-container applications. With Compose, you can create YAML files to define services and start or clean up everything with a single command. The great advantage of using Compose is that you can define your application stack in a file so that it sits at the root of your project repository (which is now version controlled) and makes it easy for others to participate in your project. Others can simply clone your repository and start writing applications. In fact, you may see a lot of projects on GitHub/GitLab doing this now. (via Using Docker Compose)
Installing Docker using official sources
The following operations need to be done under the root user, so use sudo -i
or su root
to switch to the root user to do so.
First, install some necessary packages.
Then add Docker’s GPG public key and apt source.
-
Debian
1 2
curl -sSL https://download.docker.com/linux/debian/gpg | gpg --dearmor > /usr/share/keyrings/docker-ce.gpg echo "deb [arch=$(dpkg --print-architecture) signed-by=/usr/share/keyrings/docker-ce.gpg] https://download.docker.com/linux/debian $(lsb_release -sc) stable" > /etc/apt/sources.list.d/docker.list
-
Ubuntu
1 2
curl -sSL https://download.docker.com/linux/debian/gpg | gpg --dearmor > /usr/share/keyrings/docker-ce.gpg echo "deb [arch=$(dpkg --print-architecture) signed-by=/usr/share/keyrings/docker-ce.gpg] https://download.docker.com/linux/ubuntu $(lsb_release -sc) stable" > /etc/apt/sources.list.d/docker.list
If you are in China, then you can consider using Tsinghua’s tuna source.
-
Debian
1 2
curl -sS https://download.docker.com/linux/debian/gpg | gpg --dearmor > /usr/share/keyrings/docker-ce.gpg echo "deb [arch=$(dpkg --print-architecture) signed-by=/usr/share/keyrings/docker-ce.gpg] https://mirrors.tuna.tsinghua.edu.cn/docker-ce/linux/debian $(lsb_release -sc) stable" > /etc/apt/sources.list.d/docker.list
-
Ubuntu
1 2
curl -sS https://download.docker.com/linux/debian/gpg | gpg --dearmor > /usr/share/keyrings/docker-ce.gpg echo "deb [arch=$(dpkg --print-architecture) signed-by=/usr/share/keyrings/docker-ce.gpg] https://mirrors.tuna.tsinghua.edu.cn/docker-ce/linux/ubuntu $(lsb_release -sc) stable" > /etc/apt/sources.list.d/docker.list
You can then update your system and install Docker CE.
At this point you can use the docker version
command to check if the installation was successful.
|
|
If you need a specific user to be able to run Docker in Docker rootless mode, then you can add that user to the docker group as well, for example we add the www-data
user to it.
Installing Docker Compose
Since we already have docker-compose-plugin
installed, Docker now comes with the docker compose
command, which basically replaces docker-compose
.
If some images or commands are incompatible, we can also install Docker Compose separately.
We can install the latest version directly using the official Docker distribution Github.
At this point you can use the docker-compose version
command to check if the installation was successful.
Modify Docker configuration
The following configuration will add a custom intranet IPv6 address, enable IPv6 for containers, and limit the log file size to prevent Docker logs from filling up the hard drive.
Then restart the Docker service.
|
|
Now that we have installed Docker and Docker Compose, we can start having fun installing various software.