Ubuntu 19.10上安装Docker实战
2020-04-17 本文已影响0人
复苏的兵马俑
1、卸载已安装的Docker
kevin@server:~# dpkg -l | grep docker
kevin@server:~# sudo apt-get remove docker docker-engine docker.io containerd runc
2、安装前的准备
A)更新 apt 包索引。
kevin@server:~# sudo apt-get -y update
B)安装 apt 依赖包,用于通过HTTPS来获取仓库。
kevin@server:~# sudo apt-get -y install apt-transport-https ca-certificates curl gnupg-agent software-properties-common
C)添加 GPG 密钥。
kevin@server:~# curl -fsSL https://download.docker.com/linux/ubuntu/gpg | sudo apt-key add -
OK
D)添加 Docker-ce 软件源。
kevin@server:~# sudo add-apt-repository "deb [arch=amd64] https://download.docker.com/linux/ubuntu $(lsb_release -cs) stable"
E)添加成功后更新软件包缓存。
kevin@server:~# sudo apt-get -y update
3、安装Docker
kevin@server:~# sudo apt-get -y install docker-ce docker-ce-cli containerd.io
kevin@server:~# sudo docker version
Client: Docker Engine - Community
Version: 19.03.8
API version: 1.40
Go version: go1.12.17
Git commit: afacb8b7f0
Built: Wed Mar 11 01:25:55 2020
OS/Arch: linux/amd64
Experimental: false
Server: Docker Engine - Community
Engine:
Version: 19.03.8
API version: 1.40 (minimum version 1.12)
Go version: go1.12.17
Git commit: afacb8b7f0
Built: Wed Mar 11 01:24:26 2020
OS/Arch: linux/amd64
Experimental: false
containerd:
Version: 1.2.13
GitCommit: 7ad184331fa3e55e52b890ea95e65ba581ae3429
runc:
Version: 1.0.0-rc10
GitCommit: dc9208a3303feef5b3839f4323d9beb36df0a9dd
docker-init:
Version: 0.18.0
GitCommit: fec3683
kevin@server:~# sudo docker info
Client:
Debug Mode: false
Server:
Containers: 0
Running: 0
Paused: 0
Stopped: 0
Images: 0
Server Version: 19.03.8
Storage Driver: overlay2
Backing Filesystem: <unknown>
Supports d_type: true
Native Overlay Diff: true
Logging Driver: json-file
Cgroup Driver: cgroupfs
Plugins:
Volume: local
Network: bridge host ipvlan macvlan null overlay
Log: awslogs fluentd gcplogs gelf journald json-file local logentries splunk syslog
Swarm: inactive
Runtimes: runc
Default Runtime: runc
Init Binary: docker-init
containerd version: 7ad184331fa3e55e52b890ea95e65ba581ae3429
runc version: dc9208a3303feef5b3839f4323d9beb36df0a9dd
init version: fec3683
Security Options:
apparmor
seccomp
Profile: default
Kernel Version: 5.3.0-46-generic
Operating System: Ubuntu 19.10
OSType: linux
Architecture: x86_64
CPUs: 1
Total Memory: 3.844GiB
Name: Server
ID: 3SZ6:ITPV:LA2G:B3QD:IQR3:5VMU:V3QF:DDGN:34N7:HYNX:FY4V:DENV
Docker Root Dir: /var/lib/docker
Debug Mode: false
Registry: https://index.docker.io/v1/
Labels:
Experimental: false
Insecure Registries:
127.0.0.0/8
Live Restore Enabled: false
WARNING: No swap limit support
4、修改镜像源
kevin@server:~# sudo vi /etc/docker/daemon.json
{
"registry-mirrors": [
"https://uoggbpok.mirror.aliyuncs.com",
"https://68rmyzg7.mirror.aliyuncs.com",
"http://hub-mirror.c.163.com",
"https://docker.mirrors.ustc.edu.cn",
"https://docker.mirrors.ustc.edu.cn",
"https://registry.docker-cn.com"
]
}
5、启动Docker
kevin@server:~# sudo systemctl daemon-reload
kevin@server:~# sudo systemctl start docker
kevin@server:~# sudo systemctl enable docker
Synchronizing state of docker.service with SysV service script with /lib/systemd/systemd-sysv-install.
Executing: /lib/systemd/systemd-sysv-install enable docker
6、测试Docker
kevin@server:~# sudo docker run hello-world
Unable to find image 'hello-world:latest' locally
latest: Pulling from library/hello-world
0e03bdcc26d7: Pull complete
Digest: sha256:8e3114318a995a1ee497790535e7b88365222a21771ae7e53687ad76563e8e76
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/
至此,Docker安装完成,可以开始畅游Docker了。