unbuntu安装docker

本文详细介绍了在Ubuntu系统上安装Docker的过程,包括系统版本要求、安装前的准备、安装Docker及其依赖等步骤,并提供了验证安装是否成功的示例。

此文翻译自官方文档,英文原文请参考这里
安利一篇我翻译的国外大牛的神经网络入门文章

1. 系统依赖

ubuntu需要如下版本的64bit系统

  • Yakkety 16.10
  • Xenial 16.04 (LTS)
  • Trusty 14.04 (LTS)

使用下面的命令查看正在使用的ubuntu版本:

liujinliu@liujinliu-OptiPlex-7010:~$ lsb_release -a
No LSB modules are available.
Distributor ID:	Ubuntu
Description:	Ubuntu 16.04.1 LTS
Release:	16.04
Codename:	xenial

2. 安装一些包依赖

curl是接下来按照需要使用的,linux-image-extra-*使得你安装的docker可以使用aufs存储驱动

$ sudo apt-get update

$ sudo apt-get install curl \
    linux-image-extra-$(uname -r) \
    linux-image-extra-virtual

3. 安装docker

1) 安装下面的包使得apt可以使用https的仓库地址
$ sudo apt-get install apt-transport-https \
                       ca-certificates
2) 导入官方的GPG key
$ curl -fsSL https://yum.dockerproject.org/gpg | sudo apt-key add -

使用下面的命令验证key ID 是 58118E89F3A912897C070ADBF76221572C52609D

$ apt-key fingerprint 58118E89F3A912897C070ADBF76221572C52609D
pub   4096R/2C52609D 2015-07-14
      Key fingerprint = 5811 8E89 F3A9 1289 7C07  0ADB F762 2157 2C52 609D
uid                  Docker Release Tool (releasedocker) <docker@docker.com>

使用下面的命令将相应的软件仓库地址导入,如果想使用最新的(非稳定版本)的docker,可以在main后边加个testing,在生产环境是不推荐这样做的。
当然如果加完想去掉的话,直接编辑/etc/apt/sources.list就可以了,去掉最后的testing就可以了。

3) 安装docker
$ sudo apt-get update
$ sudo apt-get -y install docker-engine

上面的命令将安装最新稳定版本的docker,也可以安装某个特定版本的docker,下面的命令看当前都有哪些稳定版本

$ sudo apt-cache madison docker-engine
docker-engine | 1.13.0-0~ubuntu-xenial | https://apt.dockerproject.org/repo ubuntu-xenial/main amd64 Packages
docker-engine | 1.12.6-0~ubuntu-xenial | https://apt.dockerproject.org/repo ubuntu-xenial/main amd64 Packages
docker-engine | 1.12.5-0~ubuntu-xenial | https://apt.dockerproject.org/repo ubuntu-xenial/main amd64 Packages
docker-engine | 1.12.4-0~ubuntu-xenial | https://apt.dockerproject.org/repo ubuntu-xenial/main amd64 Packages
docker-engine | 1.12.3-0~xenial | https://apt.dockerproject.org/repo ubuntu-xenial/main amd64 Packages
docker-engine | 1.12.2-0~xenial | https://apt.dockerproject.org/repo ubuntu-xenial/main amd64 Packages
docker-engine | 1.12.1-0~xenial | https://apt.dockerproject.org/repo ubuntu-xenial/main amd64 Packages
docker-engine | 1.12.0-0~xenial | https://apt.dockerproject.org/repo ubuntu-xenial/main amd64 Packages
docker-engine | 1.11.2-0~xenial | https://apt.dockerproject.org/repo ubuntu-xenial/main amd64 Packages
docker-engine | 1.11.1-0~xenial | https://apt.dockerproject.org/repo ubuntu-xenial/main amd64 Packages
docker-engine | 1.11.0-0~xenial | https://apt.dockerproject.org/repo ubuntu-xenial/main amd64 Packages

安装特定版本的docker使用下面的命令

sudo apt-get -y install docker-engine=<VERSION_STRING>

下面的命令验证安装是否完成:

$ sudo docker run hello-world
Unable to find image 'hello-world:latest' locally
latest: Pulling from library/hello-world
78445dd45222: Pull complete 
Digest: sha256:c5515758d4c5e1e838e9cd307f6c6a0d620b5e07e6f927b07d05f6d12a1ac8d7
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.
 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/


### 安装Docker on Ubuntu 要在Ubuntu系统上安装Docker,请按照以下步骤操作: 1. **更新系统软件包** 在开始之前,确保你的系统软件包列表是最新的: ```bash sudo apt update ``` 2. **安装必要的依赖** 安装一些必要的依赖项,以便可以使用HTTPS来访问仓库: ```bash sudo apt install apt-transport-https ca-certificates curl software-properties-common ``` 3. **添加Docker的官方GPG密钥** 为了确保下载的安全性,需要添加Docker的官方GPG密钥: ```bash curl -fsSL https://download.docker.com/linux/ubuntu/gpg | sudo gpg --dearmor -o /usr/share/keyrings/docker-archive-keyring.gpg ``` 4. **设置Docker稳定版仓库** 接下来,添加Docker的仓库到APT源中。这里我们使用阿里云的镜像来加速下载过程: ```bash echo "deb [arch=amd64 signed-by=/usr/share/keyrings/docker-archive-keyring.gpg] https://mirrors.aliyun.com/docker-ce/linux/ubuntu $(lsb_release -cs) stable" | sudo tee /etc/apt/sources.list.d/docker.list > /dev/null ``` 5. **再次更新软件包索引** 添加仓库后,再次更新软件包索引: ```bash sudo apt update ``` 6. **安装Docker CE** 现在可以安装Docker CE(社区版)了: ```bash sudo apt install docker-ce docker-ce-cli containerd.io ``` 7. **验证Docker安装** 安装完成后,可以通过运行一个测试容器来验证Docker是否正确安装: ```bash sudo docker run hello-world ``` 8. **启动并启用Docker服务** 确保Docker服务已经启动,并且设置为开机自启: ```bash sudo systemctl start docker sudo systemctl enable docker ``` 9. **检查Docker版本** 你可以通过以下命令查看Docker的版本信息: ```bash sudo docker version ``` 以上步骤应该能够帮助你在Ubuntu系统上成功安装Docker。如果你遇到任何问题,可以参考官方文档或相关社区的支持资源[^2]。 ###
评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值