Ubuntu16.04安装docker

50 篇文章 0 订阅
4 篇文章 0 订阅

官网:

 

一、安装

1. 更新

sudo apt-get update

 

2. 安装依赖包 

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

 

3. 添加官方密钥

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

 

4. 添加仓库

sudo add-apt-repository "deb [arch=amd64] https://download.docker.com/linux/ubuntu $(lsb_release -cs) stable"

 

5. 再次更新

sudo apt-get update

 

6. 安装docker

sudo apt-get install -y docker-ce

 

 

二、测试

1.  查看docker服务是否启动:systemctl status docker

baoli@ubuntu:~$ systemctl status docker
● docker.service - Docker Application Container Engine
   Loaded: loaded (/lib/systemd/system/docker.service; enabled; vendor preset: enabled)
   Active: active (running) since Sun 2019-09-08 15:19:27 CST; 44s ago
     Docs: https://docs.docker.com
Main PID: 11480 (dockerd)
    Tasks: 10
   Memory: 55.4M
      CPU: 893ms
   CGroup: /system.slice/docker.service
           └─11480 /usr/bin/dockerd -H fd:// --containerd=/run/containerd/containerd.sock
Sep 08 15:19:26 ubuntu dockerd[11480]: time="2019-09-08T15:19:26.795250717+08:00" level=wa
Sep 08 15:19:26 ubuntu dockerd[11480]: time="2019-09-08T15:19:26.795341137+08:00" level=wa
Sep 08 15:19:26 ubuntu dockerd[11480]: time="2019-09-08T15:19:26.795349613+08:00" level=wa
Sep 08 15:19:26 ubuntu dockerd[11480]: time="2019-09-08T15:19:26.796868238+08:00" level=in
Sep 08 15:19:27 ubuntu dockerd[11480]: time="2019-09-08T15:19:27.218386729+08:00" level=in
Sep 08 15:19:27 ubuntu dockerd[11480]: time="2019-09-08T15:19:27.438357184+08:00" level=in
Sep 08 15:19:27 ubuntu dockerd[11480]: time="2019-09-08T15:19:27.747766312+08:00" level=in
Sep 08 15:19:27 ubuntu dockerd[11480]: time="2019-09-08T15:19:27.749026100+08:00" level=in
Sep 08 15:19:27 ubuntu systemd[1]: Started Docker Application Container Engine.
Sep 08 15:19:27 ubuntu dockerd[11480]: time="2019-09-08T15:19:27.818603590+08:00" level=in
lines 1-21/21 (END)

若未启动,则启动docker: sudo systemctl start docker

 

2.  运行hello-world

执行:sudo docker run hello-world,提示:

baoli@ubuntu:~$ sudo docker run hello-world
Unable to find image 'hello-world:latest' locally
docker: Error response from daemon: Get https://registry-1.docker.io/v2/: net/http: request canceled while waiting for connection (Client.Timeout exceeded while awaiting headers).
See 'docker run --help'.

解决:

鉴于国内网络问题,后续拉取 Docker 镜像十分缓慢,我们可以需要配置加速器来解决,我使用的是网易的镜像地址:http://hub-mirror.c.163.com

1)sudo vim  /etc/docker/daemon.json

2)添加

{
"registry-mirrors": ["http://hub-mirror.c.163.com"]
}

3)sudo service docker restart

再次执行:sudo docker run hello-world

baoli@ubuntu:~$ sudo docker run hello-world
Unable to find image 'hello-world:latest' locally
latest: Pulling from library/hello-world
1b930d010525: Pull complete
Digest: sha256:451ce787d12369c5df2a32c85e5a03d52cbcef6eb3586dd03075f3034f10adcd
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/

 

### 回答1: 1. 更新软件源:sudo apt-get update 2. 安装依赖包:sudo apt-get install apt-transport-https ca-certificates curl software-properties-common 3. 添加Docker的GPG密钥:curl -fsSL https://download.docker.com/linux/ubuntu/gpg | sudo apt-key add - 4. 添加Docker的软件源:sudo add-apt-repository "deb [arch=amd64] https://download.docker.com/linux/ubuntu $(lsb_release -cs) stable" 5. 安装Docker:sudo apt-get update && sudo apt-get install docker-ce 6. 启动Docker服务:sudo service docker start 7. 验证是否安装成功:sudo docker run hello-world ### 回答2: 要在Ubuntu 16.04安装Docker,可以按照以下步骤进行操作: 1. 更新系统:在终端中输入以下命令,用以更新系统软件包列表。 ``` sudo apt-get update ``` 2. 安装依赖软件包:在终端中输入以下命令,安装Docker所需的软件包。 ``` sudo apt-get install apt-transport-https ca-certificates curl software-properties-common ``` 3. 添加Docker官方GPG密钥:在终端中输入以下命令,以添加Docker官方GPG密钥。 ``` curl -fsSL https://download.docker.com/linux/ubuntu/gpg | sudo apt-key add - ``` 4. 添加Docker官方软件源:在终端中输入以下命令,以添加Docker官方软件源。 ``` sudo add-apt-repository "deb [arch=amd64] https://download.docker.com/linux/ubuntu $(lsb_release -cs) stable" ``` 5. 更新软件包列表:在终端中输入以下命令,以更新软件包列表。 ``` sudo apt-get update ``` 6. 安装Docker Community Edition:在终端中输入以下命令,以安装Docker Community Edition。 ``` sudo apt-get install docker-ce ``` 7. 运行Docker安装完成后,可以使用以下命令来启动Docker服务。 ``` sudo systemctl start docker ``` 以上就是在Ubuntu 16.04安装Docker的步骤。安装完成后,你可以使用Docker命令来管理容器和镜像。 ### 回答3: 安装Docker前,请确保您的Ubuntu 16.04系统已经更新到最新版本。 1. 首先,您需要打开终端。可以按下 Ctrl+Alt+T 键来打开终端窗口。 2. 在终端中,输入以下命令来更新软件包索引: ```shell sudo apt update ``` 3. 更新完成后,安装依赖包以允许使用HTTPS通过apt来获取Docker软件包: ```shell sudo apt install apt-transport-https ca-certificates curl software-properties-common ``` 4. 接下来,添加Docker的官方GPG密钥,以确保下载的软件包的完整性和认证性: ```shell curl -fsSL https://download.docker.com/linux/ubuntu/gpg | sudo apt-key add - ``` 5. 添加Docker存储库到APT源列表中: ```shell sudo add-apt-repository "deb [arch=amd64] https://download.docker.com/linux/ubuntu $(lsb_release -cs) stable" ``` 6. 更新软件包索引: ```shell sudo apt update ``` 7. 最后,执行以下命令来安装Docker: ```shell sudo apt install docker-ce ``` 8. 安装完成后,您可以使用以下命令来检查Docker是否正确安装: ```shell sudo docker -v ``` 如果成功安装,会显示出Docker的版本号。 以上就是在Ubuntu 16.04安装Docker的步骤。希望对您有帮助!
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

hello_courage

你的鼓励将是我创作的最大动力

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

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

余额充值