Set up docker in Ubuntu
Install docker in Ubuntu
-
Set up the repository:
sudo apt-get update sudo apt-get install -y \ apt-transport-https \ ca-certificates \ curl \ gnupg \ lsb-release curl -fsSL https://download.docker.com/linux/ubuntu/gpg | sudo gpg --dearmor -o /usr/share/keyrings/docker-archive-keyring.gpg echo \ "deb [arch=amd64 signed-by=/usr/share/keyrings/docker-archive-keyring.gpg] https://download.docker.com/linux/ubuntu \ $(lsb_release -cs) stable" | sudo tee /etc/apt/sources.list.d/docker.list > /dev/null
-
Install the docker engine and tools:
sudo apt-get update sudo apt-get install -y docker-ce docker-ce-cli containerd.io docker-compose
-
Manage the docker as a non-root user:
sudo groupadd -f docker sudo usermod -aG docker $USER newgrp docker
-
Log out and log in to your desktop again.
Incorporate network setting
Before applying this configuration, ensure your host machine is behind the proxy server and uses special DNS.
Proxy
-
Create a systemd drop-in directory for the docker service:
sudo mkdir -p /etc/systemd/system/docker.service.d
-
Create a file named
/etc/systemd/system/docker.service.d/http-proxy.conf
that addsPROXY
related environment variables:[Service] Environment="HTTP_PROXY=http://proxy_ip:port" Environment="HTTPS_PROXY=https://proxy_ip:port" Environment="NO_PROXY=localhost,127.0.0.1,tic"
-
Restart the docker daemon:
sudo systemctl daemon-reload sudo systemctl restart docker
-
Verify that the configuration has been loaded and matches the changes you made:
sudo systemctl show --property=Environment docker
-
Add proxy configurations to
~/.docker/config.json
file to configure the Docker client:{ "proxies": { "default": { "httpProxy": "http://proxy_ip:port", "httpsProxy": "http://proxy_ip:port", "noProxy": "localhost,127.0.0.1,tic" } } }
DNS
-
Create a file named
/etc/docker/daemon.json
that adds thedns
key:{ "dns": [ "dns_ip", "dns_ip" ] }
-
Restart the docker daemon:
sudo systemctl restart docker
For more details, please refer the official docker document.