The purpose of this project is to provide an easy way to install Docker Engine on a Debian or Ubuntu host
Why use Docker?Docker is essential for ensuring a successful Yocto Project build because it provides Yocto Project with a known and stable environment
For example:
- Our host machine might run Debian 12 "Bookworm", or something even newer, such as from the Debian "Sid" unstable branch
- Yocto Project at the time this article was written, supports Ubuntu 18.04, 20.04, and 20.04, and Debian 11 "Bullseye"
- Our host machine may also have versions of libraries that are too new or are just incompatible with Yocto Project
- But within a Docker container, we can provide Yocto Project with an environment that looks just like Ubuntu 20.04 LTS with only the required software and versions installed
- The efficiency of Docker is far superior to running within a virtual machine because we are using the Linux kernel of the host machine
- The isolation of a Docker Container allows us to get repeatable results that are not impacted by changes we make to our host machine
- Docker Desktop includes Docker Engine, but Docker Engine does not include Docker Desktop
- Docker Desktop offer a GUI, while Docker Engine is fully command-line driven
- Docker Engine uses the Apache license, while Docker Desktop uses a Docker subscription service agreement
- Notice that while many Linux distributions are supported in the official installation instructions, I am providing instructions only for Debian and Ubuntu because these are the distributions that I and my customers run on our host machines
- If you are running Debian or a distro that is a derivative of Debian, such as Siduction or Spiral, then you should follow along with the Docker Engine installation instructions specifically for Debian
- If you are running Ubuntu or a distro that is a derivative of Ubuntu, such as Mint, then you can follow along with the Docker Engine installation instructions specifically for Ubuntu
- Yes of course! Please see the
docker.sh
installer script attached to this project. The script will run through the same instructions as shown below.
Note: This section is unnecessary if Docker was never installed on your computer
Disable Docker start with systemd
$ sudo systemctl disable docker.service && \
sudo systemctl disable containerd.service
Uninstall old versions of Docker
$ for pkg in docker.io docker-doc docker-compose podman-docker containerd runc; do sudo apt remove -y $pkg; done
Uninstall new versions of Docker
$ sudo apt remove -y docker-ce docker-ce-cli containerd.io docker-buildx-plugin docker-compose-plugin
Remove docker keyring if it is already there
$ sudo rm -f /etc/apt/keyrings/docker.gpg
Remove docker repo source list if it is already there
$ sudo rm -f /etc/apt/sources.list.d/docker.list
Remove user config directory
$ sudo rm -rf "${Home}/.docker"
Install Docker EngineUpdate the apt package index and install packages to allow apt to use a repository over HTTPS
$ sudo apt update && \
sudo apt install -y ca-certificates curl gnupg lsb-release
Install the keyring directory in case it is not already there
$ sudo install -m 0755 -d /etc/apt/keyrings
Add Docker’s official GPG key
Note: For the next instruction, run only the Debian or the Ubuntu instruction, not both
Debian
$ curl -fsSL https://download.docker.com/linux/debian/gpg | sudo gpg --dearmor -o /etc/apt/keyrings/docker.gpg
Ubuntu
$ curl -fsSL https://download.docker.com/linux/ubuntu/gpg | sudo gpg --dearmor -o /etc/apt/keyrings/docker.gpg
Make the file read-only
$ sudo chmod a+r /etc/apt/keyrings/docker.gpg
Set up the repository
Note: For the next instruction, run only the Debian or the Ubuntu instruction, not both
Debian
$ echo \
"deb [arch="$(dpkg --print-architecture)" signed-by=/etc/apt/keyrings/docker.gpg] https://download.docker.com/linux/debian \
"$(. /etc/os-release && echo "$VERSION_CODENAME")" stable" | \
sudo tee /etc/apt/sources.list.d/docker.list > /dev/null
Ubuntu
$ echo \
"deb [arch="$(dpkg --print-architecture)" signed-by=/etc/apt/keyrings/docker.gpg] https://download.docker.com/linux/ubuntu \
"$(. /etc/os-release && echo "$VERSION_CODENAME")" stable" | \
sudo tee /etc/apt/sources.list.d/docker.list > /dev/null
Install Docker Engine, containerd, and Docker Compose
$ sudo apt update && \
sudo apt install -y docker-ce docker-ce-cli containerd.io docker-buildx-plugin docker-compose-plugin
Test your system (using sudo)Verify that the Docker Engine installation is successful
Note: Notice that we are using sudo to run Docker
sudo docker run hello-world
If you see Hello from Docker!
then installation has been a success
We are following along with the Docker linux-postinstall instructions
Create docker group
$ sudo groupadd -f docker
Add your user to the docker group
$ sudo usermod -aG docker $USER
Configure Docker to start on boot with systemd
$ sudo systemctl enable docker.service && \
sudo systemctl enable containerd.service
Fix potential permissions issue
$ sudo chown "$USER":"$USER" /home/"$USER"/.docker -R && \
sudo chmod g+rwx "${HOME}/.docker" -R
Test your system (without sudo)Log out and back in to your account. This will start your next session with your membership to the docker group and allow use of Docker without sudo.
Note: Notice that we are not using sudo
$ docker run hello-world
If you see Hello from Docker!
then configuration has been a success
Please let me know in the comments if these instructions were useful for you.
If you run into any issues, please share what happened so I can update my instructions.
Comments
Please log in or sign up to comment.