docker和Docker Compose安装

CentOS下安装docker

# 命令自动补全
yum -y install bash-completion

# 启用firewall
systemctl start firewalld
systemctl enable firewalld

# 升级
yum -y update

# 重启
reboot

1,卸载旧版本,Docker 的早期版本称为 docker 或 docker-engine。如果安装了这些版本,请卸载它们及关联的依赖资源。

使用官网给出的步骤安装Docker CE版

sudo yum remove docker \
docker-client \
docker-client-latest \
docker-common \
docker-latest \
docker-latest-logrotate \
docker-logrotate \
docker-selinux \
docker-engine-selinux \
docker-engine

2.安装 Docker CE

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-config-manager --add-repo http://mirrors.aliyun.com/docker-ce/linux/centos/docker-ce.repo
】
sudo yum-config-manager --enable docker-ce-edge
sudo yum-config-manager --enable docker-ce-test
sudo yum-config-manager --disable docker-ce-edge
sudo yum makecache 
sudo yum install docker-ce

3.centos8上准备安装个docker,抛出了一个报错

[root@localhost ~]# yum install docker-ce
Extra Packages for Enterprise Linux 8 - x86_64                                                                                                                                                                              268 kB/s | 3.3 MB     00:12    
Last metadata expiration check: 0:00:02 ago on Tue 12 Nov 2019 11:53:21 PM CST.
Error: 
 Problem: package docker-ce-3:19.03.4-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.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
(try to add '--skip-broken' to skip uninstallable packages or '--nobest' to use not only best candidate packages)

 
下载支持的containerd.io然后重新下载docker

wget https://download.docker.com/linux/centos/7/x86_64/edge/Packages/containerd.io-1.2.6-3.3.el7.x86_64.rpm
yum install -y  containerd.io-1.2.6-3.3.el7.x86_64.rpm 
yum install -y docker-ce
docker -v

4.启动docker

sudo systemctl start docker

或者

service docker start

5.验证

sudo docker run hello-world

6.设置开机启动

sudo chkconfig docker on
或
systemctl enable docker.service

使用脚本自动安装

在测试或开发环境中 Docker 官方为了简化安装流程,提供了一套便捷的安装脚本,CentOS 系统上可以使用这套脚本安装:

curl -fsSL get.docker.com -o get-docker.sh

再执行

sudo sh get-docker.sh --mirror Aliyun

Docker Compose安装

官网安装步骤地址:https://docs.docker.com/compose/install/


1、安装Run this command to download the latest version of Docker Compose
sudo curl -L "https://github.com/docker/compose/releases/download/1.25.4/docker-compose-$(uname -s)-$(uname -m)" -o /usr/local/bin/docker-compose


如果github dockercompose速度较慢可以使用下面这个,效果一样
curl -L https://get.daocloud.io/docker/compose/releases/download/1.25.4/docker-compose-`uname -s`-`uname -m` > /usr/local/bin/docker-compose

 
2、赋权Apply executable permissions to the binary:
sudo chmod +x /usr/local/bin/docker-compose
 
3、Optionally, install command completion for the bash and zsh shell.
sudo ln -s /usr/local/bin/docker-compose /usr/bin/docker-compose

4、测试(查看版本)Test the installation
docker-compose --version

 

你可能感兴趣的:(Linux系统维护笔记,linux,docker)