linux下docker安装教程

188 阅读1分钟

安装docker

CentOS

$ 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 
$ sudo yum install -y docker-ce 
$ sudo systemctl enable docker 
$ sudo systemctl start docker

Debian

$ sudo apt-get install apt-transport-https ca-certificates curl gnupg2 software-properties-common 
$ curl -fsSL https://download.docker.com/linux/debian/gpg | sudo apt-key add - 
$ sudo add-apt-repository "deb [arch=amd64] https://download.docker.com/linux/debian $(lsb_release -cs) stable" 
$ sudo apt-get update 
$ sudo apt-get install docker-ce 
$ sudo systemctl enable docker 
$ sudo systemctl start docker

Fedora

$ sudo dnf -y install dnf-plugins-core 
$ sudo dnf config-manager --add-repo https://download.docker.com/linux/fedora/docker-ce.repo 
$ sudo dnf install docker-ce 
$ sudo systemctl enable docker 
$ sudo systemctl start docker

Ubuntu

$ 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 - 
$ 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 
$ sudo systemctl enable docker 
$ sudo systemctl start docker

常见问题

[elink@iZm5e9xpea3e486br8p7g3Z ~]$ sudo yum install -y docker-ce 
CentOS-8 - AppStream                                                           125 kB/s | 4.3 kB     00:00    
CentOS-8 - Base                                                                 91 kB/s | 3.8 kB     00:00    
CentOS-8 - Extras                                                               30 kB/s | 1.5 kB     00:00    
Extra Packages for Enterprise Linux 8 - x86_64                                 134 kB/s | 4.7 kB     00:00    
Docker CE Stable - x86_64                                                       13 kB/s |  22 kB     00:01    
错误:
 问题: package docker-ce-3:19.03.8-3.el7.x86_64 requires containerd.io >= 1.2.2-3, but none of the providers can be installed
  - cannot install the best candidate for the job
  - package containerd.io-1.2.10-3.2.el7.x86_64 is excluded
  - package containerd.io-1.2.13-3.1.el7.x86_64 is excluded
  - package containerd.io-1.2.2-3.3.el7.x86_64 is excluded
  - package containerd.io-1.2.2-3.el7.x86_64 is excluded
  - package containerd.io-1.2.4-3.1.el7.x86_64 is excluded
  - package containerd.io-1.2.5-3.1.el7.x86_64 is excluded
  - package containerd.io-1.2.6-3.3.el7.x86_64 is excluded
(尝试添加 '--skip-broken' 来跳过无法安装的软件包 或 '--nobest' 来不只使用最佳选择的软件包)
安装新版的containerd.io软件包

containerd.io软件包下载地址:download.docker.com/linux/cento…

[root@localhost ~]# yum -y install containerd.io-1.2.6-3.3.el7.x86_64.rpm    //升级containerd.io软件包

安装完成后重新安装Docker

修改docker默认路径

sudo vim /etc/docker/daemon.json

{
  "registry-mirrors": ["https://5typxqwj.mirror.aliyuncs.com"],
  "graph":"/mnt/docker/registry"
}
[elink@iZm5e9xpea3e486br8p7g3Z docker]$ sudo vim /etc/docker/daemon.json
[elink@iZm5e9xpea3e486br8p7g3Z docker]$ sudo systemctl daemon-reload
[elink@iZm5e9xpea3e486br8p7g3Z docker]$ sudo systemctl restart docker
[elink@iZm5e9xpea3e486br8p7g3Z docker]$ 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: 894b81a4b802e4eb2a91d1ce216b8817763c29fb
 runc version: 425e105d5a03fabd737a126ad93d62a9eeede87f
 init version: fec3683
 Security Options:
  seccomp
   Profile: default
 Kernel Version: 4.18.0-147.5.1.el8_1.x86_64
 Operating System: CentOS Linux 8 (Core)
 OSType: linux
 Architecture: x86_64
 CPUs: 2
 Total Memory: 3.692GiB
 Name: iZm5e9xpea3e486br8p7g3Z
 ID: QCP4:HLL5:TT2W:5WJO:XIFS:5YZI:FB3D:5HLP:5GAX:3PXE:3CJK:DQ6K
 Docker Root Dir: /mnt/docker/registry
 Debug Mode: false
 Registry: https://index.docker.io/v1/
 Labels:
 Experimental: false
 Insecure Registries:
  127.0.0.0/8
 Registry Mirrors:
  https://5typxqwj.mirror.aliyuncs.com/
 Live Restore Enabled: false

修改外部访问docker的端口号

  1. 编辑docker文件:/usr/lib/systemd/system/docker.service

命令:vim /usr/lib/systemd/system/docker.service

修改ExecStart行,增加内容 -H tcp://0.0.0.0:10100 ,修改后如下:

ExecStart=/usr/bin/dockerd -H tcp://0.0.0.0:10100 -H fd:// --containerd=/run/containerd/containerd.sock
  1. 重新加载docker配置
systemctl daemon-reload // 1,加载docker守护线程
systemctl restart docker // 2,重启docker