Ø Ubuntu操作系统为64位
root@ubuntu-daisy:~# uname –r // 查看ubuntu kernel version是否高于3.10
4.4.0-36-generic
Ø 更新包信息,确保恰当的使用HTTP的方法,和CA证书安装
root@ubuntu-daisy:~# apt-get update
root@ubuntu-daisy:~# apt-get install apt-transport-https ca-certificates
Ø 添加GPG key 注意有时网络加载不成功,可以再次加载一次
root@ubuntu-daisy:~# apt-key adv --keyserverhkp://p80.pool.sks-keyservers.net:80 --recv-keys58118E89F3A912897C070ADBF76221572C52609D
Ø 添加源并新增entries
root@ubuntu-daisy:~# vim /etc/apt/sources.list.d/docker.list
添加deb https://apt.dockerproject.org/repo ubuntu-xenial main并保存退出
Ø 更新APT包,并删除老的repo
root@ubuntu-daisy:~# apt-get update
root@ubuntu-daisy:~# apt-get purge lxc-docker //第一次安装就跳过
Ø 检测APT是否下载适配的 repository
root@ubuntu-daisy:~# apt-cache policy docker-engine
docker-engine:
Installed:1.12.1-0~xenial
Candidate:1.12.1-0~xenial
Version table:
*** 1.12.1-0~xenial500
500https://apt.dockerproject.org/repo ubuntu-xenial/main amd64 Packages
100/var/lib/dpkg/status
1.12.0-0~xenial500
500https://apt.dockerproject.org/repo ubuntu-xenial/main amd64 Packages
1.11.2-0~xenial500
500https://apt.dockerproject.org/repo ubuntu-xenial/main amd64 Packages
1.11.1-0~xenial500
500https://apt.dockerproject.org/repo ubuntu-xenial/main amd64 Packages
1.11.0-0~xenial500
500https://apt.dockerproject.org/repo ubuntu-xenial/main amd64 Packages
Ø 下载好repo再更新一下
root@ubuntu-daisy:~# apt-get upgrade
Ø 安装docker
root@ubuntu-daisy:~# apt-get install docker-engine
Ø 开启docker
root@ubuntu-daisy:~# service docker start
Ø 运行hello-world image
root@ubuntu-daisy:~# docker run hello-world
Hello from Docker!
This message shows that your installation appears to beworking correctly.
To generate this message, Docker took the following steps:
1. The Docker clientcontacted the Docker daemon.
2. The Docker daemonpulled the "hello-world" image from the Docker Hub.
3. The Docker daemoncreated a new container from that image which runs the
executable thatproduces the output you are currently reading.
4. The Docker daemonstreamed that output to the Docker client, which sent it
to your terminal.
安装成功!
ps:网络不需要代理的可以测试成功,但是一般公司网络有代理,会出现代理配置问题
一切安装完毕后,开始运行hello-world镜像测试也不成功
root@ubuntu-daisy:~# docker run hello-world //运行image测试
Unable to find image 'hello-world:latest' locally
Pulling repository docker.io/library/hello-world
docker: Network timed out while trying to connect tohttps://index.docker.io/v1/repositories/library/hello-world/images. You maywant to check your internet connection or if you are behind a proxy..
See 'docker run --help'.
现在显示image运行不成功,首先查看原因
使用curl 查看状态:
root@ubuntu-daisy:~# curl -v https://index.docker.io/v1/repositories/library/hello-world/images
* Trying 10.240.252.20...
* Connected to proxy-prc.web.com port 80 (#0) //说明docker http设置成功
* Establish HTTP proxy tunnel toindex.docker.io:443
> CONNECT index.docker.io:443 HTTP/1.1
> Host: index.docker.io:443
> User-Agent: curl/7.47.0
> Proxy-Connection: Keep-Alive
>
< HTTP/1.1 200 Connection established
<
* Proxy replied OK to CONNECT request
* found 173 certificates in/etc/ssl/certs/ca-certificates.crt
...
既然HTTP设置成功了,docker repository 也能下载image,只是docker无法识别本机的http,下载的Image没法在本机上显示,所以问题在于docker环境变量。(此时也可以使用wget命令获得image,只是在本机上不显示,但实际上debug下载下来了。)
root@ubuntu-daisy:~# wget hello-world
--2016-09-07 10:42:58-- http://hello-world/
Resolving proxy-prc.intel.com(proxy-prc.intel.com)... 10.240.252.16
Connecting to proxy-prc.intel.com(proxy-prc.intel.com)|10.240.252.16|:911... connected.
Proxy request sent, awaiting response... 200 OK
Length: 163 [text/html]
Saving to: ‘index.html’
index.html 100%[===================>] 163 --.-KB/s in 0s
2016-09-07 10:42:59 (27.0 MB/s) - ‘index.html’saved [163/163]
root@ubuntu-daisy:~# docker images
REPOSITORY TAG IMAGE ID CREATED SIZE
现在开始解决环境变量问题:
先查看 /etc/default/docker 文件,发现没有问题
已经为ubuntu设置了http_proxy了。
查了试了半天,才知道还需要给docker单独设代理:
root@ubuntu-daisy:~# vim/etc/systemd/system/docker.service.d/http-proxy.conf
添加http_proxy变量进去
[service] //必须要有,这是systemd格式
Environment="HTTP_PROXY=http://proxy.example.com:80/"
root@ubuntu-daisy:~#systemctl daemon-reload
root@ubuntu-daisy:~#systemctl show docker --property Environment
Environment="HTTP_PROXY=http://proxy.example.com:80/"
root@ubuntu-daisy:~#service docker start
root@ubuntu-daisy:~# dockerrun hello-world
Unable to find image'hello-world:latest' locally
latest: Pulling fromlibrary/hello-world
c04b14da8d14: Pull complete
Digest: sha256:0256e8a36e2070f7bf2d0b0763dbabdd67798512411de4cdcf9431a1feb60fd9
Status: Downloaded newerimage for hello-world:latest
Hello from Docker!
This message shows thatyour installation appears to be working correctly.
To generate this message,Docker took the following steps:
1. The Docker client contacted the Dockerdaemon.
2. The Docker daemon pulled the"hello-world" image from the Docker Hub.
3. The Docker daemon created a new containerfrom that image which runs the
executable that produces the output you arecurrently reading.
4. The Docker daemon streamed that output tothe Docker client, which sent it
to your terminal.
运行成功!
在Ubuntu 16.04(LTS) 下安装docker
最新推荐文章于 2022-03-29 23:32:05 发布