安装相关包
复制代码
1
2
3
4
5
6
7
8# 先更新一下软件源库信息 $ sudo apt-get update $ sudo apt-get install apt-transport-https ca-certificates curl software-properties-common
添加软件仓库
官方仓库
复制代码
1
2
3
4
5
6
7
8
9# 添加 Docker 官方的 GPG 密钥(为了确认所下载软件包的合法性,需要添加软件源的 GPG 密钥) $ curl -fsSL https://download.docker.com/linux/ubuntu/gpg | sudo apt-key add - # 设置稳定版本的apt仓库地址 $ sudo add-apt-repository "deb [arch=amd64] https://download.docker.com/linux/ubuntu $(lsb_release -cs) stable"
阿里云仓库
复制代码
1
2
3
4
5
6
7$ curl -fsSL https://mirrors.aliyun.com/docker-ce/linux/ubuntu/gpg | sudo apt-key add - $ sudo add-apt-repository "deb [arch=amd64] https://mirrors.aliyun.com/docker-ce/linux/ubuntu $(lsb_release -cs) stable"
安装docker
安装最新版的docker
复制代码
1
2
3$ sudo apt-get update $ sudo apt-get install docker-ce # 安装最新版的docker
如果需要安装指定版本的,使用以下命令
复制代码
1
2
3
4
5
6$ apt-cache policy docker-ce # 查看可供安装的所有docker版本 $ sudo apt-get install docker-ce=17.03.1~ce-0~ubuntu # 安装指定版本的docker `` # 检查docker是否安装成功 $ docker --version # 查看安装的docker版本
添加访问权限
这个时候运行docker的话,如果不是root用户会报错:
复制代码
1
2
3Got permission denied while trying to connect to the Docker daemon socket at unix:///var/run/docker.sock: Get http://%2Fvar%2Frun%2Fdocker.sock/v1.26/images/json: dial unix /var/run/docker.sock: connect: permission denied
看一下权限
复制代码
1
2
3
4
5
6
7$ cd /var/run $ ll | grep docker # 输出如下 drwx------ 8 root root 180 11月 21 16:36 docker -rw-r--r-- 1 root root 5 11月 21 16:35 docker.pid srw-rw---- 1 root docker 0 11月 21 16:35 docker.sock
可以看到 docker.sock 的所有者是 docker 这个组。所以我们要把当前用户添加到这个组里。
复制代码
1
2$ sudo gpasswd -a ${USER} docker
重启docker
复制代码
1
2sudo service docker restart
切换当前会话到新 group 或者重启 X 会话(*** 注意:最后一步是必须的,否则因为 groups 命令获取到的是缓存的组信息,刚添加的组信息未能生效,所以 docker images 执行时同样有错。)
复制代码
1
2newgrp - docker
运行docker测试
这个时候就可以运行helloworld测试啦~
复制代码
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23$ 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之后,测试hello-world镜像,终端提示:Unable to find image ‘hello-world:latest’ locally019-11-06
问题原因:docker服务器在国外(需要翻墙),因为我们是在国内操作无法正常拉取镜像,
解决方法1:所以就需要我们为docker设置国内阿里云的镜像加速器;需要修改配置文件 /etc/docker/daemon.json (改文件需要新创建)添加内容如下:
1 创建文件
复制代码
1
2#touch /etc/docker/daemon.json
2 添加镜像
复制代码
1
2
3
4{ "registry-mirrors": ["https://alzgoonw.mirror.aliyuncs.com"] }
3 重启docker服务
复制代码
1
2
3#systemctl restart docker #sudo systemctl status docker
4 测试helloworld 镜像
注意:如果还是不行的话就换个镜像试一下这个解决方法一般是可行的。
最后
以上就是痴情高跟鞋最近收集整理的关于Ubuntu16.04安装docker(亲测百分百有效) 还有helloworld镜像不成功的解决方法的全部内容,更多相关Ubuntu16.04安装docker(亲测百分百有效)内容请搜索靠谱客的其他文章。
本图文内容来源于网友提供,作为学习参考使用,或来自网络收集整理,版权属于原作者所有。
发表评论 取消回复