参考:https://docs.docker.com/engine/install/ubuntu/
Docker安装
设置存储库
更新apt软件包索引并安装软件包以允许apt通过HTTPS使用存储库:
sudo apt-get update && sudo apt upgrade
sudo apt-get install \
apt-transport-https \
ca-certificates \
curl \
gnupg \
lsb-release添加Docker的官方GPG密钥:
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安装DOCKER引擎
更新apt程序包索引,并安装最新版本的Docker Engine和容器化的容器,或转到下一步以安装特定版本:
sudo apt-get update
sudo apt-get install docker-ce docker-ce-cli containerd.io配置
添加用户到Docker组
sudo usermod -aG docker yjw #yjw是我的用户名
cat /etc/group | grep docker #查看查看Docker版本
docker --version
docker system info添加国内源
sudo vim /etc/docker/daemon.json添加如下
{
"registry-mirrors": ["https://alzgoonw.mirror.aliyuncs.com"]
}
{
"registry-mirrors" : [
"http://docker.mirrors.ustc.edu.cn",
"http://registry.docker-cn.com",
"https://mirror.ccs.tencentyun.com",
"http://hub-mirror.c.163.com"
],
"insecure-registries" : [
"registry.docker-cn.com",
"docker.mirrors.ustc.edu.cn"
],
"debug" : true,
"experimental" : true
}Docker中国区官方镜像
https://registry.docker-cn.com
ustc
https://docker.mirrors.ustc.edu.cn
中国科技大学
https://docker.mirrors.ustc.edu.cn
重启服务
systemctl restart docker
sudo systemctl status docker测试
sudo docker run hello-world
Hello from Docker!
This message shows that your installation appears to be working correctly.
To generate this message, Docker took the following steps:
1. The Docker client contacted the Docker daemon.
2. The Docker daemon pulled the "hello-world" image from the Docker Hub.
(amd64)
3. The Docker daemon created a new container from that image which runs the
executable that produces the output you are currently reading.
4. The Docker daemon streamed that output to the Docker client, which sent it
to your terminal.
To try something more ambitious, you can run an Ubuntu container with:
$ docker run -it ubuntu bash
Share images, automate workflows, and more with a free Docker ID:
https://hub.docker.com/
For more examples and ideas, visit:
https://docs.docker.com/get-started/查看镜像
docker image ls
REPOSITORY TAG IMAGE ID CREATED SIZE
hello-world latest d1165f221234 6 weeks ago 13.3kBDocker 命令
启动命令:
sudo systemctl start docker查看状态:
sudo systemctl status docker重启docker:
sudo systemctl restart docker关闭命令:
sudo systemctl stop dockerDocker 卸载
卸载docker:
sudo apt-get purge docker-ce docker-ce-cli containerd.io
sudo apt-get autoremove docker docker-ce docker-engine docker.io containerd runc删除docker其他没有没有卸载
dpkg -l | grep docker
sudo apt-get autoremove docker-ce-*删除docker的相关配置&目录
sudo rm -rf /etc/systemd/system/docker.service.d
sudo rm -rf /var/lib/docker
sudo rm -rf /var/lib/containerd删除所有带 rc 标记的dpkg包
dpkg -l | grep ^rc | cut -d' ' -f3 | sudo xargs dpkg --purge