Docker - Ubunut下部署
641 字
3 分钟
Docker - Ubunut下部署
Ubuntu环境下部署Docker
官方文档:https://docs.docker.com/desktop/setup/install/linux/ubuntu/
1. apt 下载 Docker 文件
官方给了 .deb 的安装包,似乎也有 apt 源,就是有点麻烦阿 …
大概是这样的、还得先安装一个 curl …
# Add Docker's official GPG key:sudo apt-get updatesudo apt-get install ca-certificates curlsudo install -m 0755 -d /etc/apt/keyringssudo curl -fsSL https://download.docker.com/linux/ubuntu/gpg -o /etc/apt/keyrings/docker.ascsudo 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/nullsudo apt-get update结果在执行 curl 想要下载 docker.asc 的时候就卡住了。还是本地安装 .deb 吧 …
在艰难的下载完 .deb 安装包使用 FTP 传输到了服务器 …
tmd 结果多试几次 curl 就通了,真的无语,我刚下好的 .deb 阿 …`
emmm 用 apt 能装,就是很慢很慢 …
配置完之后安装就可以了
sudo apt-get install docker-ce docker-ce-cli containerd.io docker-buildx-plugin docker-compose-plugin2. 测试一下 docker 是否安装成功
sudo docker run hello-world要是提示错误,记得检查一下 docker 服务有没有启动
systemctl status dockersystemctl enable dockersystemctl start docker3. 配置 docker 的镜像源
很明显在测试 hello-world 的时候,已经感觉到无法连接到 docker 官方服务器了~~(无法连接到 rockstar官方服务器)~~
所以需要配置一个镜像源~~(加速器)~~
对于使用 systemd 的系统,请在 /etc/docker/daemon.json 中写入如下内容(如果文件不存在请新建该文件):
{"registry-mirrors":["https://reg-mirror.qiniu.com/"]}然后重启服务
systemctl daemon-reloadsystemctl restart docker然而还是不行,这是为什么呢?而后发现了问题的关键
root@qianyue-VMware-Virtual-Platform:/etc/docker# curl https://hub-mirror.c.163.com/curl: (6) Could not resolve host: hub-mirror.c.163.comroot@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" ]}重启后总算有结果了,一天没白干。
root@qianyue-VMware-Virtual-Platform:/etc/docker# docker run hello-worldUnable to find image 'hello-world:latest' locallylatest: Pulling from library/hello-worlde6590344b1a5: Pull completeDigest: sha256:7e1a4e2d11e2ac7a8c3f768d4166c2defeb09d2a750b010412b6ea13de1efb19Status: 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/支持与分享
如果这篇文章对你有帮助,欢迎分享给更多人或打赏支持!













