Ubuntu 16.04 安装 Docker

本文详细介绍如何在Ubuntu系统上卸载旧版本Docker、安装最新版本并进行配置,包括设置国内镜像源、创建及加入Docker用户组等关键步骤。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

保证
1. 卸载旧版本

`sudo apt remove dokcer` 
`sudo apt remove docker.io`
`sudo apt remove docker-engine` 

2. 更新apt库

`sudo apt-get update`
  1. 安装允许HTTPS使用存储包

    sudo apt-get install apt-transport-https ca-certificates curl software-properties-common

  2. 添加官方GPG密钥

    curl -fsSL https://download.docker.com/linux/ubuntu/gpg | sudo apt-key add -

    鉴于国内网络问题,更换为国内源

    curl -fsSL https://mirrors.ustc.edu.cn/docker-ce/linux/ubuntu/gpg | sudo apt-key add -

    搜索指纹对吼8个字符确认

    sudo apt-key fingerprint XXXXXXXX

  3. 向source.list添加Docker软件源

    $ sudo add-apt-repository "deb [arch=amd64] https://mirrors.ustc.edu.cn/docker-ce/linux/ubuntu $(lsb_release -cs) stable"

  4. 安装Docker CE

    sudo apt-get update

    sudo apt-get install docker-ce

    或使用脚本安装

    curl -fsSL get.docker.com -o get-docker.sh

    sudo sh get-docker.sh --mirror Aliyun

  5. 启动docker

    sudo systemctl enable docker

    sudo systemctl start docker

  6. 建立docker用户组

    1. 建立组

      sudo groupadd docker

    2. 将当前用户加入docker组

      sudo usermod -aG docker $USER

    3. 退出终端并重新登录

  7. 测试

    docker run hello-world

    正确信息显示如下:

Unable to find image 'hello-world:latest' locally
latest: Pulling from library/hello-world
ca4f61b1923c: Pull complete
Digest: sha256:be0cd392e45be79ffeffa6b05338b98ebb16c87b255f48e297ec7f98e123905c
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://cloud.docker.com/

For more examples and ideas, visit:
 https://docs.docker.com/engine/userguide/
### 如何在 Ubuntu 16.04 上逐步安装 Docker 要在 Ubuntu 16.04安装 Docker,可以按照以下方法操作: #### 更新系统包 为了确保系统的软件包是最新的,在开始之前应更新现有的包列表。运行以下命令来完成此操作: ```bash sudo apt-get update && sudo apt-get upgrade -y ``` #### 安装必要的依赖项 某些工具可能需要额外的依赖库才能正常工作。可以通过执行以下命令来安装这些依赖项: ```bash sudo apt-get install -y apt-transport-https ca-certificates curl software-properties-common ``` 这一步是为了支持 HTTPS 方法访问 APT 存储库以及管理 GPG 密钥。 #### 添加 Docker 的官方 GPG 密钥 通过 `curl` 命令获取并添加 Docker 的官方 GPG 密钥到您的系统中: ```bash curl -fsSL https://download.docker.com/linux/ubuntu/gpg | sudo apt-key add - ``` #### 设置稳定的存储库 配置 Docker 软件源以便能够从中下载最新版本的应用程序。对于 Ubuntu 16.04 (Xenial Xerus),可使用如下命令设置稳定版仓库: ```bash sudo add-apt-repository "deb [arch=amd64] https://download.docker.com/linux/ubuntu $(lsb_release -cs) stable" ``` #### 再次更新APT索引文件 由于刚刚新增了一个外部资源地址至APT配置里头,所以再次刷新本地缓存使之生效。 ```bash sudo apt-get update ``` #### 正式安装 Docker CE(社区版) 现在已准备好实际部署容器引擎本身了——只需简单地调用下面这条指令即可实现自动化过程: ```bash sudo apt-get install -y docker-ce ``` 至此完成了整个流程[^1]。 验证服务状态是否启动成功并且正在运行当中: ```bash sudo systemctl status docker ``` 如果一切顺利的话,则应该能看到绿色字样表明其处于激活(Active)模式下运转良好;否则请查阅错误日志排查原因所在位置再做相应调整处理措施直到恢复正常为止。 最后测试一下基本功能能否正常使用情况怎么样呢?比如拉取官方镜像repository里的hello-world项目作为初次体验尝试看看效果如何吧! ```bash docker run hello-world ``` 当看到类似这样的输出信息时就代表恭喜您已经成功设置了环境啦~ > Hello from Docker! This message shows that your installation appears to be working correctly. --- ### 注意事项 虽然上述指导适用于大多数标准场景下的常规需求满足程度较高,但在特定情况下可能会遇到兼容性或其他技术难题需另行解决才行哦!
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值