docker和docker-compose
共 5628字,需浏览 12分钟
·
2020-07-28 17:47
阅读文本大概需要3分钟。
docker、dockerfile与docker-compose区别
docker:和操作系统无关的一个沙箱容器,宿主机安装的什么操作系统和其本身无关,在它基础上可以制作各种系统类型的基础服务
Dockerfile:是把手工安装docer镜像的过程变成一个配置文件的方式运行,这样每次不需要一步步手敲命令去安装了,而只是需要一个配置文件运行既可生成一个镜像
docker-compos:提供了服务和项目的概念,这样一个服务可以配置多个项目,这个服务是多个项目的集合体,启动和关闭都相对一个一个项目的启动要方便很多
0x01:docker的安装
第一步:删除旧版本和相关依赖
yum remove docker \
docker-client \
docker-client-latest \
docker-common \
docker-latest \
docker-latest-logrotate \
docker-logrotate \
docker-engine
第二步: 安装依赖
yum install -y yum-utils \
device-mapper-persistent-data \
lvm2
第三步: 配置稳定的repositories
yum-config-manager \
--add-repo \
https://download.docker.com/linux/centos/docker-ce.repo
第四步: 安装docker
yum install docker-ce docker-ce-cli containerd.io
完成后通过docker version命令查看docker的版本信息
启动:systemctl start docker
开机启动:systemctl enable docker
0x02:安装docker-compose
docker-compose的版本列表:
https://github.com/docker/compose/releases/
docker-compose主要有以下两种安装方式
方法一
curl -L \
https://github.com/docker/compose/releases/download/1.24.1/docker-compose-`uname -s`-`uname -m` > /usr/local/bin/docker-compose
添加权限
chmod +x /usr/local/bin/docker-compose
查看版本信息
docker-compose --version
但是此方法会经常因为网络的原因而无法安装
方法二
1、安装python-pip
yum -y install epel-release
yum -y install python-pip
2、安装docker-compose
pip install docker-compose
待安装完成后,执行查询版本的命令,即可安装docker-compose
docker-compose version
方式一相对简单,但是由于网络问题,常常安装不上,并且经常会断开;方式二略微麻烦,但是安装过程比较稳定。另外卸载卸载docker-compose,只需要删除二进制文件就OK了。
0x03:附录
在安装的过程中,可能会遇到一些奇奇怪怪的问题,小编在安装完docker-compose后遇到执行命令:
docker-compose --version
如下问题(异常堆栈没有保留到:
/usr/lib64/python2.7/site-packages/cryptography/__init__.py:39:
CryptographyDeprecationWarning
看样子python版本跟docker-compose不兼容问题。一不小心执行了如下命令
##强制删除已安装程序及其关联
rpm -qa|grep python|xargs rpm -ev --allmatches --nodeps
##删除所有残余文件 ##xargs,允许你对输出执行其他某些命令
whereis python |xargs rm -frv
##验证删除,返回无结果
whereis python
最终发现把python和yum全部给删除了【好大的杯具】。最终重新安装一下python和yum,只能使用rpm命令安装python和yum;执行如下命令下载如下rpm包
wget http://mirrors.163.com/centos/7/os/x86_64/Packages/libxml2-python-2.9.1-6.el7.4.x86_64.rpm
wget http://mirrors.163.com/centos/7/os/x86_64/Packages/lvm2-python-libs-2.02.186-7.el7.x86_64.rpm
wget http://mirrors.163.com/centos/7/os/x86_64/Packages/python-2.7.5-88.el7.x86_64.rpm
wget http://mirrors.163.com/centos/7/os/x86_64/Packages/python2-rpm-macros-3-32.el7.noarch.rpm
wget http://mirrors.163.com/centos/7/os/x86_64/Packages/python-backports-1.0-8.el7.x86_64.rpm
wget http://mirrors.163.com/centos/7/os/x86_64/Packages/python-backports-ssl_match_hostname-3.5.0.1-1.el7.noarch.rpm
wget http://mirrors.163.com/centos/7/os/x86_64/Packages/python-chardet-2.2.1-3.el7.noarch.rpm
wget http://mirrors.163.com/centos/7/os/x86_64/Packages/python-devel-2.7.5-88.el7.x86_64.rpm
wget http://mirrors.163.com/centos/7/os/x86_64/Packages/python-iniparse-0.4-9.el7.noarch.rpm
wget http://mirrors.163.com/centos/7/os/x86_64/Packages/python-kitchen-1.1.1-5.el7.noarch.rpm
wget http://mirrors.163.com/centos/7/os/x86_64/Packages/python-libs-2.7.5-88.el7.x86_64.rpm
wget http://mirrors.163.com/centos/7/os/x86_64/Packages/python-pycurl-7.19.0-19.el7.x86_64.rpm
wget http://mirrors.163.com/centos/7/os/x86_64/Packages/python-rpm-macros-3-32.el7.noarch.rpm
wget http://mirrors.163.com/centos/7/os/x86_64/Packages/python-setuptools-0.9.8-7.el7.noarch.rpm
wget http://mirrors.163.com/centos/7/os/x86_64/Packages/python-srpm-macros-3-32.el7.noarch.rpm
wget http://mirrors.163.com/centos/7/os/x86_64/Packages/python-urlgrabber-3.10-10.el7.noarch.rpm
wget http://mirrors.163.com/centos/7/os/x86_64/Packages/python-virtualenv-15.1.0-2.el7.noarch.rpm
wget http://mirrors.163.com/centos/7/os/x86_64/Packages/rpm-4.11.3-43.el7.x86_64.rpm
wget http://mirrors.163.com/centos/7/os/x86_64/Packages/rpm-build-4.11.3-43.el7.x86_64.rpm
wget http://mirrors.163.com/centos/7/os/x86_64/Packages/rpm-build-libs-4.11.3-43.el7.x86_64.rpm
wget http://mirrors.163.com/centos/7/os/x86_64/Packages/rpm-python-4.11.3-43.el7.x86_64.rpm
wget http://mirrors.163.com/centos/7/os/x86_64/Packages/rpm-sign-4.11.3-43.el7.x86_64.rpm
wget http://mirrors.163.com/centos/7/os/x86_64/Packages/yum-3.4.3-167.el7.centos.noarch.rpm
wget http://mirrors.163.com/centos/7/os/x86_64/Packages/yum-metadata-parser-1.1.4-10.el7.x86_64.rpm
wget http://mirrors.163.com/centos/7/os/x86_64/Packages/yum-plugin-aliases-1.1.31-53.el7.noarch.rpm
wget http://mirrors.163.com/centos/7/os/x86_64/Packages/yum-plugin-fastestmirror-1.1.31-53.el7.noarch.rpm
wget http://mirrors.163.com/centos/7/os/x86_64/Packages/yum-plugin-protectbase-1.1.31-53.el7.noarch.rpm
wget http://mirrors.163.com/centos/7/os/x86_64/Packages/yum-utils-1.1.31-53.el7.noarch.rpm
wget http://mirrors.163.com/centos/7/os/x86_64/Packages/python-backports-ssl_match_hostname-3.5.0.1-1.el7.noarch.rpm
wget http://mirrors.163.com/centos/7/os/x86_64/Packages/python-ipaddress-1.0.16-2.el7.noarch.rpm
wget http://mirrors.163.com/centos/7/os/x86_64/Packages/libxml2-2.9.1-6.el7.4.x86_64.rpm
wget http://mirrors.163.com/centos/7/os/x86_64/Packages/libxml2-devel-2.9.1-6.el7.4.x86_64.rpm
wget http://mirrors.163.com/centos/7/os/x86_64/Packages/rpm-libs-4.11.3-43.el7.x86_64.rpm
wget http://mirrors.163.com/centos/7/os/x86_64/Packages/rpm-devel-4.11.3-43.el7.x86_64.rpm
要注意的是有的包名字可能会更新,那么就去找相似的去替代即可。
安装python
rpm -ivh python-* rpm-python-*
安装yum
rpm -ivh yum-*
如果安装过程出现了类似下面的代码,这是包与包之间的依赖关系的问题,只需要卸载已经安装的包【rpm -e 包名(没有.rpm后缀)】,然后先安装依赖包,即可。
☆
往期精彩
☆
02 Nacos源码编译
关注我
每天进步一点点