一、根據官網文檔提示:
https://docs.docker.com/install/
二、實際安裝操作
centos:
https://docs.docker.com/install/linux/docker-ce/centos/ 可能很慢
卸載舊版本:
較舊的Docker版本稱爲docker
或docker-engine
。如果已安裝這些程序,請卸載它們以及相關的依賴項。
$ sudo yum remove docker \
docker-client \
docker-client-latest \
docker-common \
docker-latest \
docker-latest-logrotate \
docker-logrotate \
docker-engine
安裝所需的軟件包。yum-utils提供了yum-config-manager ,並且devicemapper存儲驅動程序需要device-mapper-persistent-data和lvm2
sudo yum install -y yum-utils \
device-mapper-persistent-data \
lvm2
使用以下命令來設置穩定的存儲庫。
sudo yum-config-manager \
--add-repo \
https://download.docker.com/linux/centos/docker-ce.repo
安裝最新版本的Docker Engine-Community和containerd
$ sudo yum install docker-ce docker-ce-cli containerd.io
這一步可能失敗,網絡太慢,嘗試了3次,放棄了......
配置本地yum源來安裝docker,
清華大學yum源 https://mirrors.cnnic.cn/
$ mv /etc/yum.repos.d/CentOS-Base.repo /etc/yum.repos.d/CentOS-Base.repo.bak
$ vim /etc/yum.repos.d/CentOS-Base.repo
# CentOS-Base.repo
#
# The mirror system uses the connecting IP address of the client and the
# update status of each mirror to pick mirrors that are updated to and
# geographically close to the client. You should use this for CentOS updates
# unless you are manually picking other mirrors.
#
# If the mirrorlist= does not work for you, as a fall back you can try the
# remarked out baseurl= line instead.
#
#
[base]
name=CentOS-$releasever - Base
baseurl=https://mirrors.tuna.tsinghua.edu.cn/centos/$releasever/os/$basearch/
#mirrorlist=http://mirrorlist.centos.org/?release=$releasever&arch=$basearch&repo=os
gpgcheck=1
gpgkey=file:///etc/pki/rpm-gpg/RPM-GPG-KEY-CentOS-7
#released updates
[updates]
name=CentOS-$releasever - Updates
baseurl=https://mirrors.tuna.tsinghua.edu.cn/centos/$releasever/updates/$basearch/
#mirrorlist=http://mirrorlist.centos.org/?release=$releasever&arch=$basearch&repo=updates
gpgcheck=1
gpgkey=file:///etc/pki/rpm-gpg/RPM-GPG-KEY-CentOS-7
#additional packages that may be useful
[extras]
name=CentOS-$releasever - Extras
baseurl=https://mirrors.tuna.tsinghua.edu.cn/centos/$releasever/extras/$basearch/
#mirrorlist=http://mirrorlist.centos.org/?release=$releasever&arch=$basearch&repo=extras
gpgcheck=1
gpgkey=file:///etc/pki/rpm-gpg/RPM-GPG-KEY-CentOS-7
#additional packages that extend functionality of existing packages
[centosplus]
name=CentOS-$releasever - Plus
baseurl=https://mirrors.tuna.tsinghua.edu.cn/centos/$releasever/centosplus/$basearch/
#mirrorlist=http://mirrorlist.centos.org/?release=$releasever&arch=$basearch&repo=centosplus
gpgcheck=1
enabled=0
gpgkey=file:///etc/pki/rpm-gpg/RPM-GPG-KEY-CentOS-7
$ yum clean all # 清除系統所有的yum緩存
$ yum makecache # 生成yum緩存
使用yum直接安裝,簡單粗暴:
yum install docker -y
[root@cloud-container other]# systemctl start docker
[root@cloud-container other]# docker -v
Docker version 1.13.1, build cccb291/1.13.1
配置國內docker鏡像源
# 添加 網易鏡像源 把下面的內容添加到文件
vi /etc/docker/daemon.json
{
"registry-mirrors": [
"http://hub-mirror.c.163.com"
]
}
重啓服務
systemctl restart docker
查看docker 信息
[root@cloud-container ~]# docker info
Containers: 0
Running: 0
Paused: 0
Stopped: 0
Images: 0
Server Version: 1.13.1
Storage Driver: overlay2
Backing Filesystem: xfs
Supports d_type: true
Native Overlay Diff: true
Logging Driver: journald
Cgroup Driver: systemd
Plugins:
Volume: local
Network: bridge host macvlan null overlay
Swarm: inactive
Runtimes: docker-runc runc
Default Runtime: docker-runc
Init Binary: /usr/libexec/docker/docker-init-current
containerd version: (expected: aa8187dbd3b7ad67d8e5e3a15115d3eef43a7ed1)
runc version: 66aedde759f33c190954815fb765eedc1d782dd9 (expected: 9df8b306d01f59d3a8029be411de015b7304dd8f)
init version: fec3683b971d9c3ef73f284f176672c44b448662 (expected: 949e6facb77383876aeff8a6944dde66b3089574)
Security Options:
seccomp
WARNING: You're not using the default seccomp profile
Profile: /etc/docker/seccomp.json
selinux
Kernel Version: 3.10.0-1062.el7.x86_64
Operating System: CentOS Linux 7 (Core)
OSType: linux
Architecture: x86_64
Number of Docker Hooks: 3
CPUs: 4
Total Memory: 1.777 GiB
Name: cloud-container
ID: LFUA:4UOD:6H4T:SAFV:HBXS:RNFX:BIZH:3V5L:HB2Y:A34X:D42Q:EKK3
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:
http://hub-mirror.c.163.com
Live Restore Enabled: false
Registries: docker.io (secure)
ok 啓動第一個docker容器
瀏覽器中輸入centos ip 和 端口
Completed!