1.首先,到官网下载 Xenial 内核对应的的 deb 包。
如果需要下载其他 Ubuntu 内核版本的 deb 包,可以从此处进入下载。
2.安装 Docker
sudo dpkg -i docker-ce_17.09.1~ce-0~ubuntu_amd64.deb
3.推荐使用阿里云 Docker 加速器
由此链接进入可申请阿里云专属的加速器地址。
申请后执行相应的命令:
sudo tee /etc/docker/daemon.json <<-'EOF'
{
"registry-mirrors": ["https://yourownkey.mirror.aliyuncs.com"]
}
EOF
sudo systemctl daemon-reload
sudo systemctl restart docker
4.验证 Docker 是否安装完毕
sudo docker run hello-world
该操作将会自动从官网拉取镜像并执行,如果有如下输出,说明 Docker 安装成功了。
Unable to find image 'hello-world:latest' locally
latest: Pulling from library/hello-world
ca4f61b1923c: Pull complete
Digest: sha256:be0cd392e45be79ffeffa6b05338b98ebb16c87b255f48e297ec7f98e123905c
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/
也可以使用以下命令查看 Docker 是否安装成功:
sudo docker info
看控制台是否有类似如下输出:
Containers: 1
Running: 0
Paused: 0
Stopped: 1
Images: 1
Server Version: 17.09.1-ce
Storage Driver: overlay2
Backing Filesystem: extfs
Supports d_type: true
Native Overlay Diff: true
Logging Driver: json-file
Cgroup Driver: cgroupfs
Plugins:
Volume: local
Network: bridge host macvlan null overlay
Log: awslogs fluentd gcplogs gelf journald json-file logentries splunk syslog
Swarm: inactive
Runtimes: runc
Default Runtime: runc
Init Binary: docker-init
containerd version: 06b9cb35161009dcb7123345749fef02f7cea8e0
runc version: 3f2f8b84a77f73d38244dd690525642a72156c64
init version: 949e6fa
Security Options:
apparmor
seccomp
Profile: default
Kernel Version: 4.10.0-28-generic
Operating System: Ubuntu 16.04.3 LTS
OSType: linux
Architecture: x86_64
CPUs: 2
Total Memory: 3.839GiB
Name: charley-virtual-machine
ID: 2RWL:MJ5G:KR4T:PSWT:XVV5:QV6S:YH2K:AFQS:ZUQP:LNJW:SQNO:BVTW
Docker Root Dir: /var/lib/docker
Debug Mode (client): false
Debug Mode (server): false
Registry: https://index.docker.io/v1/
Experimental: false
Insecure Registries:
127.0.0.0/8
Registry Mirrors:
https://2zn744kl.mirror.aliyuncs.com/
Live Restore Enabled: false
WARNING: No swap limit support
5.将当前用户加入到 docker 用户组中
默认情况下, docker 命令会使用 Unix socket 与 Docker 引擎通讯。而只有 root 用户和 docker 组的用户才可以访问 Docker 引擎的 Unix socket。出于安全考虑,一般 Linux 系统上不会直接使用 root 用户。因此,更好地做法是将需要使用 docker 的用户加入 docker 用户组。
以上节选自《Docker技术入门与实战(第2版)》。
首先确保本机已存在 docker 用户组,如果没有可以建立一个:
sudo groupadd docker
然后将当前用户加入到 docker 用户组:
sudo usermod -aG docker $USER
注销当前用户再重新登陆,就可以在当前用户使用 Docker 了。
6.如果想通过源而不是 deb 方式进行安装,可以参考附件中的参考资料。
附:参考资料
Ubuntu 16.04安装Docker
Ubuntu 16.04 安装 Docker
完。
网友评论