Docker在Ubuntu上安装

Docker在Ubuntu上安装


1.安装:

在Ubuntu上安装Docker:

(1)添加Docker仓库:

shell 复制代码
# 更新包索引
sudo apt update

# 安装依赖
sudo apt install apt-transport-https ca-certificates curl software-properties-common

# 添加Docker的官方GPG密钥
curl -fsSL https://download.docker.com/linux/ubuntu/gpg | sudo apt-key add -

# 添加Docker仓库
sudo add-apt-repository "deb [arch=amd64] https://download.docker.com/linux/ubuntu $(lsb_release -cs) stable"

(2)安装Docker CE(Docker社区版):

shell 复制代码
# 更新包索引
sudo apt update

# 安装Docker社区版(Docker CE)
sudo apt install docker-ce

(3)验证是否安装成功:

shell 复制代码
# 运行hello-world镜像来验证Docker是否安装成功
sudo docker run hello-world

(4)添加用户到docker组(可选):

如果你不想每次使用Docker命令时都输入sudo,可以将你的用户添加到docker组:

shell 复制代码
sudo usermod -aG docker $USER

然后,注销并重新登录以使组变更生效。


2.问题:

(1)Docker守护进程未运行:

shell 复制代码
# 运行hello-world镜像来验证Docker是否安装成功
sudo docker run hello-world

# ========================================================
# 报错1:
docker: Cannot connect to the Docker daemon at unix:///var/run/docker.sock. Is the docker daemon running?. See 'docker run --help'.

# 解决:
#检查Docker守护进程是否正在运行:
sudo systemctl status docker
#如果服务没有运行,你可以使用以下命令启动它:
sudo systemctl start docker

(2)网络访问,需要代理:

shell 复制代码
# 运行hello-world镜像来验证Docker是否安装成功
sudo docker run hello-world

# ========================================================
# 报错2:
Unable to find image 'hello-world:latest' locally
docker: Error response from daemon: Get "https://registry-1.docker.io/v2/":  net/http: request canceled while waiting for connection (Client.Timeout exceeded while awaiting headers).
See 'docker run --help'.
"

# 原因:网络问题,需要代理
# 参考链接:https://www.cnblogs.com/gnuorg/p/18570325
# docker_daemon.sh编写以下内容,使用sudo ./docker_daemon.sh执行即可(注意会覆盖docker_daemon.sh)
 #!/bin/sh
cat <<-EOF > /etc/docker/daemon.json
{
  "registry-mirrors": [
    "https://docker.linkedbus.com",
    "https://docker.xuanyuan.me"
    ]
}
EOF
sudo systemctl daemon-reload
sudo systemctl restart docker

.


声明:资源可能存在第三方来源,若有侵权请联系删除!

相关推荐
fetasty10 小时前
rustfs加picgo图床搭建
docker
蝎子莱莱爱打怪1 天前
GitLab CI/CD + Docker Registry + K8s 部署完整实战指南
后端·docker·kubernetes
小p2 天前
docker学习7:docker 容器的通信方式
docker
小p2 天前
docker学习5:提升Dockerfile水平的5个技巧
docker
小p2 天前
docker学习3:docker是怎么实现的?
docker
小p3 天前
docker学习: 2. 构建镜像Dockerfile
docker
小p4 天前
docker学习: 1. docker基本使用
docker
崔小汤呀4 天前
Docker部署Nacos
docker·容器
缓解AI焦虑4 天前
Docker + K8s 部署大模型推理服务:资源划分与多实例调度
docker·容器
1candobetter5 天前
Docker Compose Build 与 Up 的区别:什么时候必须重建镜像
docker·容器·eureka