Set up the repository
Update the apt package index and install packages to allow apt to use a repository over HTTPS:
1
2
|
sudo apt-get update
sudo apt-get install ca-certificates curl gnupg
|
Add Docker’s official GPG key:
1
2
3
|
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
|
Use the following command to set up the repository:
1
2
3
4
|
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
|
Update the apt package index:
Install Docker Engine
Install Docker Engine, containerd, and Docker Compose.
To install the latest version, run:
1
|
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.
1
|
sudo docker run hello-world
|
安装 docker compose
To download and install the Compose CLI plugin, run:
1
2
3
|
DOCKER_CONFIG=${DOCKER_CONFIG:-$HOME/.docker}
mkdir -p $DOCKER_CONFIG/cli-plugins
curl -SL https://github.com/docker/compose/releases/download/v2.20.2/docker-compose-linux-x86_64 -o $DOCKER_CONFIG/cli-plugins/docker-compose
|
Apply executable permissions to the binary:
1
|
chmod +x $DOCKER_CONFIG/cli-plugins/docker-compose
|
Test the installation.
以非 Root 用户身份执行 Docker
默认情况下,只有 root
或者 有 sudo
权限的用户可以执行 Docker
命令。
想要以非 root
用户执行 Docker
命令,你需要将你的用户添加到 Docker
用户组,该用户组在 Docker CE
软件包安装过程中被创建。想要这么做,输入:
1
|
sudo usermod -aG docker $USER
|
$USER
是一个环境变量,代表当前用户名。
登出,并且重新登录,以便用户组信息刷新。
docker 开机启动
目前,在 wsl ubuntu 上安装docker后,已经支持 docker 开机启动了。
wsl ubuntu 也支持使用 systemctl 命令了。
开机启动
1
|
systemctl enable docker
|
禁止开机启动
1
|
systemctl disable docker
|
卸载 docker
在卸载 Docker
之前,移除所有的容器,镜像,卷和网络。
运行下面的命令停止所有正在运行的容器,并且移除所有的 docker
对象:
1
2
|
docker container stop $(docker container ls -aq)
docker system prune -a --volumes
|
现在可以使用apt
像卸载其他软件包一样来卸载 Docker
:
1
2
|
sudo apt purge docker-ce
sudo apt autoremove
|
修改docker数据存储路径
wsl
ubuntu
默认安装在 c
盘,希望将 docker
的数据存储路径(默认为 /var/lib/docker
)修改到 d
盘。
添加 /etc/docker/daemon.json
文件,内容如下
1
2
3
4
5
6
|
{
"registry-mirrors": ["https://registry.docker-cn.com"],
"data-root": "/mnt/d/data/docker",
"log-driver":"json-file",
"log-opts": {"max-size":"100m"}
}
|
docker
启动失败。wls ubuntu docker
可能不支持将文件存储到 windows
磁盘。
将 /var/lib/docker
拷贝到 d
盘,报错,应该是 windows
磁盘不支持这些特殊文件。
1
2
3
4
5
|
hekai@thinkpad-l14:~$ sudo mv /var/lib/docker /mnt/d/data/docker
mv: cannot create special file '/mnt/d/data/docker/volumes/backingFsBlockDev': Operation not supported
mv: cannot create special file '/mnt/d/data/docker/volumes/docker-centos7-slurm-cluster_mysql/_data/mysql.sock': Operation not supported
mv: cannot create special file '/mnt/d/data/docker/overlay2/3a272b47e6ae28aa475f3eea705bdb2bdeb83dc97c6feb91cc20e6c49bbc004b-init/work/work/#23d': Operation not supported
mv: cannot create special file '/mnt/d/data/docker/overlay2/2a012b89cc6a205c6c8a148abae32a5e735695b52a54e2e3e792c2a5e88a00af-init/work/work/#23f': Operation not supported
|
wsl ubuntu docker
暂不更改存储位置了。
参考:
https://docs.docker.com/engine/install/ubuntu/
https://docs.docker.com/compose/install/linux/#install-the-plugin-manually
https://zhuanlan.zhihu.com/p/143156163
https://blog.csdn.net/m0_58684193/article/details/127554527