本帖最后由 灰哥哥 于 2018-10-13 09:41 编辑
1、卸载旧版本的Docker
旧版本的Docker被称作docker或者docker-engine,Docker CE(社区版)包现在被叫做docker-ce。如果之前安装过了,需要先卸载:
- sudo apt-get remove docker docker-engine docker.io
复制代码 2、设置存储库
2.1 更新apt安装包索引
2.2 安装软件包以允许apt通过HTTPS- sudo apt-get install apt-transport-https ca-certificates curl software-properties-common
复制代码 2.3 添加Docker官方的GPG密钥
- curl -fsSL https://download.docker.com/linux/ubuntu/gpg | sudo apt-key add -
复制代码 2.4 安装稳定版仓库
- sudo add-apt-repository "deb [arch=amd64] https://download.docker.com/linux/ubuntu $(lsb_release -cs) stable"
复制代码 3、安装Docker CE版
3.1 更新apt安装包索引
3.2 安装最新版的Docker CE
- sudo apt-get install docker-ce
复制代码
3.3 如果不想安装最新版的Docker,可以先查看可安装版本
- apt-cache madison docker-ce
复制代码 部分输出结果:
- docker-ce | 17.12.0~ce-0~ubuntu | https://download.docker.com/linux/ubuntu xenial/stable amd64 Packages
- docker-ce | 17.09.1~ce-0~ubuntu | https://download.docker.com/linux/ubuntu xenial/stable amd64 Packages
- ……
- docker-ce | 17.03.1~ce-0~ubuntu-xenial | https://download.docker.com/linux/ubuntu xenial/stable amd64 Packages
- ……
复制代码
列表的内容取决于启用了哪个存储库。第二列是Docker版本号。第三列是存储库名称,它指明了软件包来自哪个存储存储库,并通过扩展其稳定性级别。要安装特定版本,需要将本本字符串附加到包名称。
安装指定版本如下:
- sudo apt-get install docker-ce=<VERSION>
复制代码
3.4 通过运行hello-world镜像验证Docker CE已被正确安装
- sudo docker run hello-world
复制代码 这个命令下载一个测试图像并在容器中运行。容器运行时,会打印一条信息消息并退出。
注意:这个时候可能会出现无法连接的情况,这是由于国内访问Docker Hub不稳定,运用下面的命令配置我们的镜像加速器。
编辑下面文件,修改一行代码(增加黄色高亮部分),如下:
- sudo vim /lib/systemd/system/docker.service
复制代码 修改的行改如下:
ExecStart=/usr/bin/dockerd -H fd:// --registry-mirror=https://registry.docker-cn.com
输入以下命令后注销并重新登录:
- sudo systemctl daemon-reload
- sudo systemctl restart docker
复制代码
再次运行hello-world:
- sudo docker run hello-world
复制代码
若出现以下信息则表明安装成功: - Unable to find image 'hello-world:latest' locally
- latest: Pulling from library/hello-world
- ca4f61b1923c: Pull complete
- Digest: sha256:66ef312bbac49c39a89aa9bcc3cb4f3c9e7de3788c944158df3ee0176d32b751
- 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://cloud.docker.com/
- For more examples and ideas, visit:
- https://docs.docker.com/engine/userguide/
复制代码4、以非root用户身份管理Docker docker守护程序绑定到一个Unix套接字而不是TCP端口。默认情况下,Unix套接字由用户拥有root,其他用户只能使用它来访问它sudo。
该docker守护进程始终运行的root用户。如果不想在运行docker命令时使用sudo,需要创建一个名为docker的Unix Group向其中添加用户。
当docker守护进程启动时,它使得Unix套接字的所有权可以被docker组读/写。
同时也解决docker-compose up -d 问题
ERROR: Couldn’t connect to Docker daemon at http+docker://localunixsocket - is it running?
If it’s at a non-standard location, specify the URL with the DOCKER_HOST environment variable.
4.1创建docker组并添加用户
4.1.1 创建docke组
说明: 若docker安装时此组已创建好了,此步可以忽略
4.1.2 将自己的用户添加到docker组中
假设用户名为:myEdgex - sudo usermod -aG docker myEdgex
复制代码
4.1.3 注销并重新登陆以重新验证组成员关系。
如果在虚拟机上进行测试,则可能需要重新启动虚拟机才能使更改生效。
sudo service docker restart
然后退出当前用户比如切换为root,再次切换为用户名
4.1.4 验证不需要sudo运行docker命令
- sudo systemctl enable docker
复制代码
5、安装docker-compose
5.1 下载最新版本的docker-compose
- sudo curl -L https://github.com/docker/compose/releases/download/1.18.0/docker-compose-`uname -s`-`uname -m` -o /usr/local/bin/docker-compose
复制代码
5.2 更改二进制文件的权限,使其能够运行
- sudo chmod +x /usr/local/bin/docker-compose
复制代码
5.3 测试安装
|