Skip to content

Instantly share code, notes, and snippets.

@Hansimov
Last active January 5, 2024 18:34
Show Gist options
  • Save Hansimov/412eb8bd6d7af3c9e96afad9811cd755 to your computer and use it in GitHub Desktop.
Save Hansimov/412eb8bd6d7af3c9e96afad9811cd755 to your computer and use it in GitHub Desktop.
Install and setup docker

Following this guide

Add Docker's official GPG key:

sudo apt-get update
sudo apt-get install ca-certificates curl gnupg
sudo install -m 0755 -d /etc/apt/keyrings
curl -fsSL https://download.docker.com/linux/ubuntu/gpg | sudo gpg --dearmor -o /etc/apt/keyrings/docker.gpg
sudo chmod a+r /etc/apt/keyrings/docker.gpg

Add the repository to Apt sources:

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
sudo apt-get update

Install packages:

sudo apt-get install docker-ce docker-ce-cli containerd.io docker-buildx-plugin docker-compose-plugin

Verify that the Docker Engine installation is successful by running the hello-world image:

sudo docker run hello-world

If last command cannot be executed successfully, this might be due to proxy issues.

sudo mkdir -p /etc/systemd/system/docker.service.d
sudo touch /etc/systemd/system/docker.service.d/proxy.conf

Write to /etc/systemd/system/docker.service.d/proxy.conf:

[Service]
Environment="HTTP_PROXY=http://<server>:<port>"
Environment="HTTPS_PROXY=http://<server>:<port>"
Environment="NO_PROXY=localhost,127.0.0.1,.example.com"

Reload to make it work:

sudo systemctl daemon-reload
sudo systemctl restart docker

If you would like to use other mirrors:

Create /etc/docker/daemon.json:

{
    "registry-mirrors" : [
    "https://registry.docker-cn.com",
    "http://hub-mirror.c.163.com",
    "https://docker.mirrors.ustc.edu.cn",
    "https://cr.console.aliyun.com",
    "https://mirror.ccs.tencentyun.com"
  ]
}

Reload to make it work:

sudo systemctl daemon-reload
sudo systemctl restart docker
@Hansimov
Copy link
Author

Remove all images with <none>:

sudo docker rmi $(sudo docker images -f "dangling=true" -q)

@Hansimov
Copy link
Author

Hansimov commented Jan 5, 2024

Install docker-compose

sudo curl -SL https://github.com/docker/compose/releases/download/v2.23.3/docker-compose-linux-x86_64 -o /usr/local/bin/docker-compose
sudo chmod +x /usr/local/bin/docker-compose

References:

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment