Install Docker - caprivm/virtualization GitHub Wiki
caprivm ([email protected])
Updated: January 2, 2023 Ref: https://docs.docker.com/engine/install/ubuntu/
This page shows how to install docker and docker-compose on a virtual machine. The installation tests were performed on a server with the following features:
Feature | Value |
---|---|
OS Used | Ubuntu 22.04 LTS |
vCPU | 4 |
RAM (GB) | 8 |
Disk (GB) | 50 |
Home user | ubuntu |
The contents of the page are:
- Description
- Install Docker and Docker Compose
-
Install
docker-compose
Plugin Manually - Configure Docker to start on boot
- Troubleshooting
To install docker
, perform the following steps. First, install docker
engine:
sudo apt-get update
sudo apt-get install -y apt-transport-https ca-certificates curl gnupg lsb-release software-properties-common net-tools
sudo mkdir -p /etc/apt/keyrings
curl -fsSL https://download.docker.com/linux/ubuntu/gpg | sudo gpg --dearmor -o /etc/apt/keyrings/docker.gpg
echo "deb [arch=$(dpkg --print-architecture) signed-by=/etc/apt/keyrings/docker.gpg] https://download.docker.com/linux/ubuntu $(lsb_release -cs) stable" | sudo tee /etc/apt/sources.list.d/docker.list > /dev/null
sudo apt-get update
sudo apt-get install docker-ce docker-ce-cli containerd.io docker-compose-plugin
If you would like to use Docker as a non-root user, you should now consider adding your user to the docker
group with something like:
sudo groupadd docker
sudo usermod -aG docker $USER
exec "$SHELL"
Remember to restart your session to take effect. You can verify that Docker Engine is installed correctly by running the hello-world
image.
docker run hello-world
docker ps -a
# CONTAINER ID IMAGE COMMAND CREATED STATUS PORTS NAMES
# c2cd42ed2e31 hello-world "/hello" 5 seconds ago Exited (0) 4 seconds ago unruffled_boyd
If you prefer to manually install the plugin for docker-compose
, you can use the following procedure. To download and install the Compose CLI plugin, run:
DOCKER_CONFIG=${DOCKER_CONFIG:-$HOME/.docker}
mkdir -p $DOCKER_CONFIG/cli-plugins
curl -SL https://github.com/docker/compose/releases/download/v2.7.0/docker-compose-linux-x86_64 -o $DOCKER_CONFIG/cli-plugins/docker-compose
This command downloads the latest release of Docker Compose (from the Compose releases repository) and installs Compose for the active user under $HOME
directory. Give admin permissions to file and move to any $PATH
folder:
chmod +x $DOCKER_CONFIG/cli-plugins/docker-compose
sudo mv $DOCKER_CONFIG/cli-plugins/docker-compose /usr/local/bin/docker-compose
Test the installation:
docker-compose version
# Docker Compose version 2.7.0
You can run Docker Compose on macOS, Windows, and 64-bit Linux. On Linux, you can download the Docker Compose binaries from the Compose repository release page on GitHub. Follow the instructions from the link, which involve running the curl
command in your terminal to download the binaries. These step-by-step instructions are also included below.
NOTE: At time of writing, the
docker-compose
version is2.14.2
. Change according to your requiriments.
sudo curl -L "https://github.com/docker/compose/releases/download/v2.14.2/docker-compose-$(uname -s)-$(uname -m)" -o /usr/local/bin/docker-compose
sudo chmod +x /usr/local/bin/docker-compose
sudo ln -s /usr/local/bin/docker-compose /usr/bin/docker-compose
Test the installation using:
docker-compose --version
# Docker Compose version v2.14.2
Most current Linux distributions (RHEL, CentOS, Fedora, Debian, Ubuntu 16.04 and higher) use systemd
to manage which services start when the system boots. On Debian and Ubuntu, the Docker service is configured to start on boot by default. To automatically start Docker and Containerd on boot for other distros, use the commands below:
sudo systemctl enable docker.service
sudo systemctl enable containerd.service
To disable this behavior, use disable
instead.
sudo systemctl disable docker.service
sudo systemctl disable containerd.service
If you initially ran Docker CLI commands using sudo
before adding your user to the docker
group, you may see the following error, which indicates that your ~/.docker/
directory was created with incorrect permissions due to the sudo
commands.
WARNING: Error loading config file: /home/user/.docker/config.json -
stat /home/user/.docker/config.json: permission denied
To fix this problem, either remove the ~/.docker/
directory (it is recreated automatically, but any custom settings are lost), or change its ownership and permissions using the following commands:
sudo chown "$USER":"$USER" /home/"$USER"/.docker -R
sudo chmod g+rwx "$HOME/.docker" -R