学习Docker首先要学习安装,我们这里学习的是docker在ubuntu上的安装,首先打开docker的网站。https://docs.docker.com/engine/installation/linux/ubuntu/ 这篇文档是介绍怎么在ubuntu上安装的。Docker有两种安装版本,一种是CE,一种是EE。CE就是社区版,而EE是企业版。应该是学习,那么我们就安装社区版就好。
1. 操作系统需求
安装Docker,我们需要64位版本的ubuntu版本。包括下面三种:
- Yakkety 16.10
- Xenial 16.04 (LTS)
- Trusty 14.04 (LTS)
我们使用lsb_release命令来查看:
buddyyuan@buddyyuan-VirtualBox:~$ lsb_release -a No LSB modules are available. Distributor ID: Ubuntu Description: Ubuntu 16.04.2 LTS Release: 16.04 Codename: xenial buddyyuan@buddyyuan-VirtualBox:~$ getconf LONG_BIT 64
可以看到我们的满足条件,是Xenial 16.04 (LTS),并且是64位的。
2. 卸载旧的docker
在安装新的Docker之前,需要卸载旧的版本:
buddyyuan@buddyyuan-VirtualBox:~$ sudo apt-get remove docker docker-engine [sudo] password for buddyyuan: Reading package lists... Done Building dependency tree Reading state information... Done E: Unable to locate package docker-engine
3. 设置软件仓库
我们安装社区版,也就是docker-ce。
3.1 安装https包
sudo apt-get install \ apt-transport-https \ ca-certificates \ curl \ software-properties-common
3.2 添加Docker官方的GPG key
curl -fsSL https://download.docker.com/linux/ubuntu/gpg | sudo apt-key add –
添加完成来验证一下,Key fingerprint必须等于下列值:9DC8 5822 9FC7 DD38 854A E2D8 8D81 803C 0EBF CD88
buddyyuan@buddyyuan-VirtualBox:~$ sudo apt-key fingerprint 0EBFCD88 pub 4096R/0EBFCD88 2017-02-22 Key fingerprint = 9DC8 5822 9FC7 DD38 854A E2D8 8D81 803C 0EBF CD88 uid Docker Release (CE deb) <docker@docker.com> sub 4096R/F273FCD8 2017-02-22
3.3 添加稳定版的仓库
有两种仓库,一种是stable ,也就是稳定版,这种版本一个季度更新一次。而另外一种是Edge 版本,这种版本是每个月更新一次。
这里我选择stable 版本的软件仓库。
$ sudo add-apt-repository \ "deb [arch=amd64] https://download.docker.com/linux/ubuntu \ $(lsb_release -cs) \ stable"
4. 开始安装Docker
4.1 更新APT包
sudo apt-get update
4.2 安装docker ce版本
sudo apt-get install docker-ce
4.3 生产环境选择
在生产环境当中,你应该选择安装指定的版本,而不是最新的版本。
buddyyuan@buddyyuan-VirtualBox:~$ apt-cache madison docker-ce docker-ce | 17.03.1~ce-0~ubuntu-xenial | https://download.docker.com/linux/ubuntu xenial/stable amd64 Packages docker-ce | 17.03.0~ce-0~ubuntu-xenial | https://download.docker.com/linux/ubuntu xenial/stable amd64 Packages
这里可以看到,第一列是docker-ce,第二列是版本,一个是17.0.3.1,一个是17.0.3.0。第三列是stable软件仓库
使用下列命令来进行指定版本安装:
sudo apt-get install docker-ce=<VERSION>
4.4 验证docker是否正确安装
验证docker是否正常,我们运行hello-world image
buddyyuan@buddyyuan-VirtualBox:~$ 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/library/hello-world/manifests/latest: Get https://auth.docker.io/token?scope=repository%3Alibrary%2Fhello-world%3Apull& service=registry.docker.io: net/http: TLS handshake timeout. See 'docker run --help'.
没想到这里报错了。从报错上看,应该是网络问题。在国内容易被墙。只好开了VPN软件,多试几次。
buddyyuan@buddyyuan-VirtualBox:~$ 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终于安装完成。默认的所有的东西都安装在这个/var/lib/docker下面:
buddyyuan@buddyyuan-VirtualBox:/var/lib/docker$ cd /var/lib/docker buddyyuan@buddyyuan-VirtualBox:/var/lib/docker$ sudo ls -lrt total 36 drwx------ 4 root root 4096 5月 11 00:43 plugins drwx------ 2 root root 4096 5月 11 00:43 volumes drwx------ 3 root root 4096 5月 11 00:43 image drwx------ 5 root root 4096 5月 11 00:43 aufs drwx------ 2 root root 4096 5月 11 00:43 trust drwxr-x--- 3 root root 4096 5月 11 00:43 network drwx------ 2 root root 4096 5月 11 00:43 swarm drwx------ 2 root root 4096 5月 11 00:50 tmp drwx------ 3 root root 4096 5月 11 00:50 containers
Comments 2
受教了!呵呵!
Posted 14 5月 2017 at 09:00 ¶我也有过博客,不过那都是很多年前的事情了!
Posted 20 7月 2017 at 07:41 ¶Post a Comment