Docker - Ubunut下部署

641 字
3 分钟
Docker - Ubunut下部署

Ubuntu环境下部署Docker#

官方文档:https://docs.docker.com/desktop/setup/install/linux/ubuntu/

1. apt 下载 Docker 文件#

官方给了 .deb 的安装包,似乎也有 apt 源,就是有点麻烦阿 …

大概是这样的、还得先安装一个 curl …

Terminal window
# Add Docker's official GPG key:
sudo apt-get update
sudo apt-get install ca-certificates curl
sudo install -m 0755 -d /etc/apt/keyrings
sudo curl -fsSL https://download.docker.com/linux/ubuntu/gpg -o /etc/apt/keyrings/docker.asc
sudo chmod a+r /etc/apt/keyrings/docker.asc
# Add the repository to Apt sources:
# 它其实是一段指令,别害怕,直接输入到bash里就行 ...
echo \
"deb [arch=$(dpkg --print-architecture) signed-by=/etc/apt/keyrings/docker.asc] https://download.docker.com/linux/ubuntu \
$(. /etc/os-release && echo "${UBUNTU_CODENAME:-$VERSION_CODENAME}") stable" | \
sudo tee /etc/apt/sources.list.d/docker.list > /dev/null
sudo apt-get update

结果在执行 curl 想要下载 docker.asc 的时候就卡住了。还是本地安装 .deb 吧 …

在艰难的下载完 .deb 安装包使用 FTP 传输到了服务器 …

tmd 结果多试几次 curl 就通了,真的无语,我刚下好的 .deb 阿 …`

emmm 用 apt 能装,就是很慢很慢 …

配置完之后安装就可以了

Terminal window
sudo apt-get install docker-ce docker-ce-cli containerd.io docker-buildx-plugin docker-compose-plugin

2. 测试一下 docker 是否安装成功#

Terminal window
sudo docker run hello-world

要是提示错误,记得检查一下 docker 服务有没有启动

Terminal window
systemctl status docker
systemctl enable docker
systemctl start docker

3. 配置 docker 的镜像源#

很明显在测试 hello-world 的时候,已经感觉到无法连接到 docker 官方服务器了~~(无法连接到 rockstar官方服务器)~~

所以需要配置一个镜像源~~(加速器)~~

对于使用 systemd 的系统,请在 /etc/docker/daemon.json 中写入如下内容(如果文件不存在请新建该文件):

{"registry-mirrors":["https://reg-mirror.qiniu.com/"]}

然后重启服务

Terminal window
systemctl daemon-reload
systemctl restart docker

然而还是不行,这是为什么呢?而后发现了问题的关键

Terminal window
root@qianyue-VMware-Virtual-Platform:/etc/docker# curl https://hub-mirror.c.163.com/
curl: (6) Could not resolve host: hub-mirror.c.163.com
root@qianyue-VMware-Virtual-Platform:/etc/docker# nslookup https://hub-mirror.c.163.com/
;; communications error to 127.0.0.53#53: timed out

很明显是未能解析域名,然后才发现国内的公共 docker 源都挂了 …

然后偷偷找了应该能用的镜像源(后续可能随时会更新)

{
"registry-mirrors": [
"https://docker.1ms.run",
"https://docker.xuanyuan.me"
]
}

重启后总算有结果了,一天没白干。

Terminal window
root@qianyue-VMware-Virtual-Platform:/etc/docker# docker run hello-world
Unable to find image 'hello-world:latest' locally
latest: Pulling from library/hello-world
e6590344b1a5: Pull complete
Digest: sha256:7e1a4e2d11e2ac7a8c3f768d4166c2defeb09d2a750b010412b6ea13de1efb19
Status: Downloaded newer image for hello-world:latest
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 - Ubunut下部署
https://springtsuki.xucjno.com/posts/springtsuki/notes/docker/2-ubuntu下部署docker/
作者
SpringTsuki
发布于
2025-03-25
许可协议
CC BY-NC-SA 4.0
Profile Image of the Author
SpringTsuki
你好,我是浅月。
公告
浅月的开发小窝!欢迎你来到这里!
音乐
封面

音乐

暂未播放

0:000:00
暂无歌词
分类
标签
站点统计
文章
17
分类
8
标签
16
总字数
19,430
运行时长
0
最后活动
0 天前
站点信息
构建平台
GitHub Actions
博客版本
Firefly v6.13.5
文章许可
CC BY-NC-SA 4.0

文章目录