手动添加软件源
添加软件源
首先需要安装 apt-transport-https 等软件包支持https协议的源:
$ sudo apt update
$ sudo apt install apt-transport-https ca-certificates curl software-properties-common
添加源的gpg密钥:
$ curl -fsSL https://download.docker.com/linux/ubuntu/gpg | sudo apt-key add - OK
确认导入指纹为 “9DC8 5822 9FC7 DD38 854A E2D8 8D81 803C 0EBF CD88”的 GPG 公钥:
$ sudo apt-key fingerprint 0EBFCD88
获取当前操作系统的代号:
$ lsb_release -cs
// Ubuntu 16.04 LTS: Xenial
// Ubuntu 18.04 LTS: bionic
添加Docker稳定版的官方软件源:
$ sudo add-apt-repository "deb [arch=amd64] https://download.docker.com/linux/ubuntu Xenial stable"
添加成功后,再次更新apt软件包缓存:
$ sudo apt-get update
安装Docker
$ sudo apt install -y docker-ce
自动化脚本安装
官网脚本
$ curl -sSL https://get.docker.com | sh
国内镜像
$ curl -fsSL get.docker.com -o get-docker.sh
$ sudo sh get-docker.sh --mirror Aliyun
安装后日志分析
// docker客户端
Client:
Version: 18.09.2
API version: 1.39
Go version: go1.10.6
Git commit: 6247962
Built: Sun Feb 10 04:13:50 2019
OS/Arch: linux/amd64
Experimental: false
// docker服务端 - 社区版
Server: Docker Engine - Community
Engine:
Version: 18.09.2
API version: 1.39 (minimum version 1.12)
Go version: go1.10.6
Git commit: 6247962
Built: Sun Feb 10 03:42:13 2019
OS/Arch: linux/amd64
Experimental: false
// 如果你不想用root账号使用 Docker,你应该把你的用户加入到 “docker” 分组中(安装过程中已经新建了docker分组)
If you would like to use Docker as a non-root user, you should now consider
adding your user to the "docker" group with something like:
sudo usermod -aG docker your-user
// 记住你必须退出并重新登录才能生效
Remember that you will have to log out and back in for this to take effect!
// 警告:将用户添加到“docker”组将授予运行容器的能力,这些容器可用于获取docker主机上的root权限。
WARNING: Adding a user to the "docker" group will grant the ability to run
containers which can be used to obtain root privileges on the
docker host.
Refer to https://docs.docker.com/engine/security/security/#docker-daemon-attack-surface
for more information.
** DOCKER ENGINE - ENTERPRISE **
Test drive additional security features by activating Docker Engine - Enterprise.
* Leverage FIPS 140-2 validated encryption
* Run only trusted images with digital signature enforcement
// 参考资源
** Learn more at https://dockr.ly/engine1 **
ACTIVATE your own engine to Docker Engine - Enterprise using:
sudo docker engine activate
添加用户到docker分组【可选】
默认情况下,docker
命令会使用 Unix socket 与 Docker 引擎通讯。而只有 root
用户和 docker
组的用户才可以访问 Docker 引擎的 Unix socket。出于安全考虑,一般 Linux 系统上不会直接使用 root
用户。因此,更好地做法是将需要使用 docker
的用户加入 docker
用户组。
$ sudo usermod -aG docker $USER
# 如果没有该分组就新建 sudo groupadd docker
退出当前终端并重新登录
启动 Docker CE
$ sudo systemctl enable docker
$ sudo systemctl start docker
// 或
$ sudo service docker start
测试 Docker 是否安装正确
$ docker run hello-world
执行以上命令,若能正常输出以下信息,则说明安装成功。
Unable to find image 'hello-world:latest' locally
latest: Pulling from library/hello-world
1b930d010525: Pull complete
Digest: sha256:2557e3c07ed1e38f26e389462d03ed943586f744621577a99efb77324b0fe535
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://hub.docker.com/
For more examples and ideas, visit:
https://docs.docker.com/get-started/
国内镜像
请在 /etc/docker/daemon.json
中写入如下内容(如果文件不存在请新建该文件) :
{
"registry-mirrors": [
"https://registry.docker-cn.com"
]
}
注意,一定要保证该文件符合 json 规范,否则 Docker 将不能启动。
之后重新启动服务:
$ sudo systemctl daemon-reload
$ sudo systemctl restart docker
配置加速器之后,如果拉取镜像仍然十分缓慢,请手动检查加速器配置是否生效,在命令行执行 docker info
,如果从结果中看到了如下内容,说明配置成功。
Registry Mirrors:
https://registry.docker-cn.com/