旧版本的 Docker 被称作 docker 或者 docker-engine,Docker CE(社区版)包现在被叫做 docker-ce。如果之前安装过了,需要先卸载:
sudo apt-get remove docker docker-engine docker.io
sudo apt-get update
sudo apt-get install \
apt-transport-https \
ca-certificates \
curl \
software-properties-common
curl -fsSL https://download.docker.com/linux/ubuntu/gpg | sudo apt-key add -
确保现在系统已经拥有密钥指纹的后八个字符串:9DC8 5822 9FC7 DD38 854A E2D8 8D81 803C 0EBF CD88
输入指令:
sudo apt-key fingerprint 0EBFCD88
显示结果:
pub 4096R/0EBFCD88 2017-02-22
密钥指纹 = 9DC8 5822 9FC7 DD38 854A E2D8 8D81 803C 0EBF CD88
uid Docker Release (CE deb) <docker@docker.com>
sub 4096R/F273FCD8 2017-02-22
sudo add-apt-repository \
"deb [arch=amd64] https://download.docker.com/linux/ubuntu \
$(lsb_release -cs) \
stable"
sudo apt-get update
sudo apt-get install docker-ce
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>
然后 Docker 守护进程就会自动启动安装了。
sudo docker run hello-world
这个命令下载一个测试图像并在容器中运行。容器运行时,会打印一条信息消息并退出。
Notice:这个时候可能会出现无法连接的情况,这是由于国内访问 Docker Hub 不稳定。我们可以注册一个阿里云账户,获得一个专属免费的加速器地址(传送门)。然后运用下面的命令配置我们的镜像加速器:
sudo mkdir -p /etc/docker
sudo vim /etc/docker/daemon.json
将以下内容写入文本:
{
"registry-mirrors": ["自己的镜像地址"]
}
输入以下命令后注销并重新登录:
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/
检查版本信息:
sudo docker version
显示信息如下:
Client:
Version: 17.12.0-ce
API version: 1.35
Go version: go1.9.2
Git commit: c97c6d6
Built: Wed Dec 27 20:11:19 2017
OS/Arch: linux/amd64
Server:
Engine:
Version: 17.12.0-ce
API version: 1.35 (minimum version 1.12)
Go version: go1.9.2
Git commit: c97c6d6
Built: Wed Dec 27 20:09:53 2017
OS/Arch: linux/amd64
Experimental: false
docke r守护程序绑定到一个 Unix 套接字而不是 TCP 端口。默认情况下,Unix 套接字由用户拥有 root,其他用户只能使用 sudo 来访问它。该 docker 守护进程始终运行的 root 用户。如果不想在运行 docker 命令时使用 sudo,需要创建一个名为 docker 的 Unix Group 向其中添加用户。当 docker 守护进程启动时,它使得 Unix 套接字的所有权可以被 docker 组读/写。
要创建 docker 组并添加用户:
sudo groupadd docker
sudo usermod -aG docker 用户名
如果在虚拟机上进行测试,则可能需要重新启动虚拟机才能使更改生效。
sudo service docker restart
docker run hello-world
sudo systemctl enable docker
sudo systemctl enable docker
sudo rm -rf /var/lib/docker
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
sudo chmod +x /usr/local/bin/docker-compose
docker-compose --version
参考文档:https://docs.docker.com/compose/install/#install-compose
应用实例:https://docs.docker.com/compose/
https://docs.docker.com/engine/installation/linux/docker-ce/ubuntu/#upgrade-docker-ce
https://docs.docker.com/engine/installation/linux/linux-postinstall/
https://yq.aliyun.com/articles/110806?spm=a2c1q.8351553.0.0.5186d9c11wgjkh
http://blog.csdn.net/rickey17/article/details/72809384
http://www.tinylab.org/use-docker-without-sudo/