Docker Installation
Install from repository
official
# Add repo and Install packages
sudo apt update
sudo apt install -y curl gnupg2 software-properties-common apt-transport-https ca-certificates
curl -fsSL https://download.docker.com/linux/ubuntu/gpg | sudo apt-key add -
sudo add-apt-repository "deb [arch=amd64] https://download.docker.com/linux/ubuntu $(lsb_release -cs) stable"
sudo apt update
sudo apt install -y containerd.io docker-ce docker-ce-cli
aliyun
sudo apt update
sudo apt install -y curl gnupg2 software-properties-common apt-transport-https ca-certificates
curl -fsSL https://mirrors.aliyun.com/docker-ce/linux/ubuntu/gpg | sudo apt-key add -
sudo add-apt-repository "deb [arch=amd64] https://mirrors.aliyun.com/docker-ce/linux/ubuntu $(lsb_release -cs) stable"
sudo apt update
# list all docker-ce version
apt list -a docker-ce
sudo apt install -y containerd.io docker-ce=5:20.10.16~3-0~ubuntu-focal docker-ce-cli=5:20.10.16~3-0~ubuntu-focal
Install from offline
Download binary files from this link.
Docker Configuration
Operations without needing root privileges
modify existing user accounts to add an existing user (in this case, ‘finuks’) to group called ‘docker’.
sudo usermod -aG docker finuks
Customize Docker daemon
Create daemon json config file
sudo vim /etc/docker/daemon.json
Add the following content:
- dns: specifies the DNS servers that will be used by containers created. When a container is started, it will use these DNS servers for resolving domain names.
- exec-opts: specify additional options that are passed to the runtime when executing containers. sets the cgroup driver used by Docker to systemd
- log-driver: specifies the logging driver that will be used by containers created. stores container logs as JSON files on the host machine.
- log-opts: specify additional options for the logging driver. sets the maximum size of each log file to 100 megabytes before it is rotated or compressed.
- storage-driver: specifies the storage driver that will be used by Docker to manage container and image storage. utilizes the overlay2 storage driver for better performance and features.
- insecure-registries: This setting allows you to specify a list of private or insecure Docker registries that should be considered acceptable for use with Docker, even if they are not secure (i.e., they do not use HTTPS).
{
"dns": [
"223.5.5.5",
"119.29.29.29"
],
"exec-opts": [
"native.cgroupdriver=systemd"
],
"log-driver": "json-file",
"log-opts": {
"max-size": "100m"
},
"storage-driver": "overlay2",
"insecure-registries": [
"registry.docker.home",
"registry1.example.com"
]
}
enable docker remote API
Navigate to /lib/systemd/system in your terminal and open docker.service file
vim /lib/systemd/system/docker.service
Find the line which starts with ExecStart and adds -H=tcp://0.0.0.0:2375 to make it look like
ExecStart=/usr/bin/dockerd -H=fd:// -H=tcp://0.0.0.0:2375
Save the Modified File
Reload the docker daemon
systemctl daemon-reload
Restart the container
sudo service docker restart
Test if it is working by using this command, if everything is fine below command should return a JSON
curl http://localhost:2375/images/json
To test remotely, use the PC name or IP address of Docker Host
Configure tools proxy
such as docker pull
and docker login
.
# directory for custom configurations or overrides of Docker's systemd service
mkdir -p /etc/systemd/system/docker.service.d
# file contain proxy info
vim /etc/systemd/system/docker.service.d/http-proxy.conf
Write the following content into the file http-proxy.conf
:
[Service]
Environment="HTTP_PROXY=127.0.0.1:8889"
Environment="HTTPS_PROXY=127.0.0.1:8889"
Environment="NO_PROXY=localhost,127.0.0.1,ccr.ccs.tencentyun.com"
You need to restart the Docker service to apply the proxy configuration.
# let system to pick up changes of systemd unit files
sudo systemctl daemon-reload
# stop the current Docker service with its old configuration, load in your new configuration settings, and start Docker again using these new settings.
sudo systemctl restart docker
Containers use proxy directly
Create and Modify the ~/.docker/config.json
file of the user who starts the container.
{
"proxies": {
"default": {
"httpProxy": "http://127.0.0.1:8889",
"httpsProxy": "http://127.0.0.1:8889",
"noProxy": "*.test.example.com,.example2.com,127.0.0.0/8"
}
}
}
You need to restart the Docker service to apply the proxy configuration.
# let system to pick up changes of systemd unit files
sudo systemctl daemon-reload
# stop the current Docker service with its old configuration, load in your new configuration settings, and start Docker again using these new settings.
sudo systemctl restart docker
Log into third-party image repository
Use the following code to log in to my Tencent Cloud image repository.
docker login --username=100011942350 ccr.ccs.tencentyun.com
Container use NVIDIA GPUs
install NVIDIA GPU drivers on host machine
The following command content is for reference only regarding installation ideas:
# Verify ubuntu driver
sudo apt install ubuntu-drivers-common
ubuntu-drivers devices
# Install the recommended driver
sudo ubuntu-drivers autoinstall
# Reboot the machine
sudo reboot
# After the reboot, test if the driver is installed correctly
nvidia-smi
install nvidia-docker2 driver
# Add the package repositories
distribution=$(. /etc/os-release;echo $ID$VERSION_ID)
curl -s -L https://nvidia.github.io/nvidia-docker/gpgkey | sudo apt-key add -
curl -s -L https://nvidia.github.io/nvidia-docker/$distribution/nvidia-docker.list | sudo tee \
/etc/apt/sources.list.d/nvidia-docker.list
# Install nvidia-docker2
sudo apt update
sudo apt list -a nvidia-docker2
sudo apt install nvidia-docker2=2.11.0-1
sudo systemctl restart docker
modify config file of daemon defaut runtime
- default-runtime: specifies the runtime to use when executing containers if one isn’t specified by the user or as part of an image.
{
"dns": [
"223.5.5.5",
"119.29.29.29"
],
"default-runtime": "nvidia",
"runtimes": {
"nvidia": {
"path": "/usr/bin/nvidia-container-runtime",
"runtimeArgs": []
}
},
"exec-opts": [
"native.cgroupdriver=systemd"
],
"log-driver": "json-file",
"log-opts": {
"max-size": "100m"
},
"storage-driver": "overlay2",
"insecure-registries": [
"registry.docker.home",
"registry1.example.com"
]
}