ubuntu下docker的安装

本文档详述了在 Ubuntu 18.04 系统上安装 Docker CE 的过程,包括更新系统、添加 Docker 仓库、安装 Docker 以及验证安装是否成功。通过运行 'hello-world' 镜像来检查 Docker 是否正常工作。

可以在官网根据文档进行安装,我这里展示我的安装过程

环境  Ubuntu 18.04.5 LTS

步骤 :

sudo apt-get remove docker docker-engine docker.io containerd runc
sudo apt-get update
sudo apt-get install apt-transport-https  ca-certificates curl  gnupg lsb-release
 curl -fsSL https://download.docker.com/linux/ubuntu/gpg | sudo gpg --dearmor -o /usr/share/keyrings/docker-archive-keyring.gpg
#我的机器架构是x86_64 / amd64
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
 sudo apt-get update
 sudo apt-get install docker-ce docker-ce-cli containerd.io
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 的步骤 #### 确认 Ubuntu 版本 为了确保兼容性,在开始之前应当验证当前使用的 Ubuntu 版本。这可以通过终端命令实现: ```bash lsb_release -a ``` 此命令会显示详细的发行版信息[^2]。 #### 更新软件包索引并安装依赖项 更新本地的 APT 软件包索引,这是任何新软件安装前推荐的操作: ```bash sudo apt-get update ``` 接着可以安装一些必要的工具来辅助后续过程: ```bash sudo apt-get install apt-transport-https ca-certificates curl software-properties-common ``` 这些命令将设置系统的 HTTPS 传输支持和其他必需组件[^1]。 #### 添加 Docker 官方 GPG 密钥 通过下面这条指令向系统添加来自 Docker 的官方安全密钥: ```bash curl -fsSL https://download.docker.com/linux/ubuntu/gpg | sudo apt-key add - ``` 该操作有助于验证所下载文件的真实性与完整性[^4]。 #### 设置稳定版本仓库 配置稳定的 Docker 库作为源之一: ```bash sudo add-apt-repository "deb [arch=amd64] https://download.docker.com/linux/ubuntu $(lsb_release -cs) stable" ``` 这里 `$(lsb_release -cs)` 自动获取正确的分发代号名称用于匹配特定版本的 Ubuntu[^3]。 #### 执行实际的 Docker 安装 完成上述准备工作之后,就可以正式安装 Docker CE (社区版): ```bash sudo apt-get update sudo apt-get install docker-ce docker-ce-cli containerd.io ``` 这段脚本不仅会拉取最新可用版本的 Docker 引擎及其 CLI 工具,还会一并处理其他可能需要的相关库。 #### 启动服务并测试安装情况 最后一步是启动 Docker 并将其设为开机自启的服务项目: ```bash sudo systemctl start docker sudo systemctl enable docker ``` 为了检验一切正常工作,尝试运行一个简单的容器实例: ```bash sudo docker run hello-world ``` 如果一切顺利,则说明已经成功完成了整个流程。
评论 2
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值