Docker的安装
1.首先将yum包更新到最新
yum update
期间要选择确认,输入 y 即可
或者使用 yum -y update
2.安装需要的软件包, yum-util 提供yum-config-manager功能,另外两个是devicemapper驱动依赖的
yum install -y yum-utils device-mapper-persistent-data lvm2
此步骤可能不需要,根据实际需求安装
3.配置docker的yum源
yum-config-manager --add-repo http://download.docker.com/linux/centos/docker-ce.repo(中央仓库)
yum-config-manager --add-repo http://mirrors.aliyun.com/docker-ce/linux/centos/docker-ce.repo(阿里仓库)
以上源2选1即可
4.可以查看所有仓库中所有docker版本,并选择特定版本安装
yum list docker-ce --showduplicates | sort -r
5.根据自己的需求,选择版本安装即可:
例如:yum install docker-ce-18.06.1.ce
6.启动与停止docker并且将docker做成服务
systemctl start/stop/restart docker
将Docker添加(取消)到自动启动
systemctl enable/disable docker
以上Docker配置完毕
Docker-Compose安装
使用PIP安装
首先安装Pip
yum -y install epel-release
yum -y install python-pip
pip install --upgrade pip
pip install --upgrade"pip < 21.0"
最后安装
pip install docker-compose
若安装遇到如下错误:
Cannot uninstall 'requests'. It is a distutils installed project and thus we cannot accurately determine which files belong to it which would lead to only a partial uninstall.
pip install -I requests==2.9
使用二进制安装
sudo curl -L https://github.com/docker/compose/releases/download/1.24.1/docker-compose-`uname -s`-`uname -m` -o /usr/local/bin/docker-compose
sudo chmod +x /usr/local/bin/docker-compose 配置执行权限
docker-compose --version 查看版本号
若出现错误,一般需要安装gcc相关内容:
yum install -y gcc
yum install gcc libffi-devel python-devel openssl-devel -y
pip install six --user -U
具体没有测试,安装好前两个后,顺利安装完成
直接安装PIP3,使用PIP3安装DockerCompose
1.安装python3-pip
yum -y install epel-release
yum -y install python3-pip
pip3 install --upgrade pip --default-timeout=100 -i http://pypi.douban.com/simple --trusted-host pypi.douban.com
yum install gcc libffi-devel python-devel openssl-devel -y
2.安装docker-compose
pip3 --default-timeout=100 install docker-compose --ignore-installed requests -i http://pypi.douban.com/simple --trusted-host pypi.douban.com
或
pip3 --default-timeout=100 install docker-compose --ignore-installed requests -i https://mirrors.aliyun.com/pypi/simple
若有问题,则可以重新安装,或不指定通过其它镜像安装
pip3 uninstall docker-py dockerdocker-compose
pip install --ignore-installed requests
配置日志
全局配置:
vim /etc/docker/daemon.json
{
"registry-mirrors": ["http://hub-mirror.c.163.com","https://registry.docker-cn.com","https://docker.mirrors.ustc.edu.cn"],
"log-driver": "json-file",
"log-opts": { "max-size": "100m", "max-file": "5"}
}
私有服务配置:
docker-compose.yml中配置
logging:
driver: "json-file"
options:
max-size: "100m" #日志限制大小100m
max-file: "5" #保留5份