一键安装docker及docker-compose

1、创建docker存放相关文件目录,该目录可自己定义。2、添加相关文件,可在网盘提取。其中docker-20.10.9.tgz和docker-compose为安装包,也可根据需要在网上下载,注意docker-compose安装包下载后需要改名为docker-compose
链接:https://pan.baidu.com/s/1de98IS6tfxodagaAsJvsZQ
提取码:h4ta

一键安装docker及docker-compose_第1张图片
daemon.json文件
一键安装docker及docker-compose_第2张图片

{
  "registry-mirrors": ["https://kksxo8ii.mirror.aliyuncs.com"],
  "log-driver":"json-file",
  "log-opts":{"max-size":"100m"}

docker.service文件
一键安装docker及docker-compose_第3张图片

[Unit]
Description=Docker Application Container Engine
Documentation=https://docs.docker.com
After=network-online.target firewalld.service
Wants=network-online.target
   
[Service]
Type=notify
# the default is not to use systemd for cgroups because the delegate issues still
# exists and systemd currently does not support the cgroup feature set required
# for containers run by docker
ExecStart=/usr/bin/dockerd -H tcp://0.0.0.0:2375 -H unix://var/run/docker.sock
ExecReload=/bin/kill -s HUP $MAINPID
# Having non-zero Limit*s causes performance problems due to accounting overhead
# in the kernel. We recommend using cgroups to do container-local accounting.
LimitNOFILE=infinity
LimitNPROC=infinity
LimitCORE=infinity
# Uncomment TasksMax if your systemd version supports it.
# Only systemd 226 and above support this version.
#TasksMax=infinity
TimeoutStartSec=0
# set delegate yes so that systemd does not reset the cgroups of docker containers
Delegate=yes
# kill only the docker process, not all processes in the cgroup
KillMode=process
# restart the docker process if it exits prematurely
Restart=on-failure
StartLimitBurst=3
StartLimitInterval=60s
   
[Install]
WantedBy=multi-user.target

install.sh文件(一键安装脚本)
一键安装docker及docker-compose_第4张图片

echo  '创建docker相关目录'
mkdir -p /etc/docker
cp daemon.json /etc/docker
echo '解压tar包...'
tar -xvf ./docker-20.10.9.tgz
echo '将docker目录移到/usr/bin目录下...'
cp -f ./docker/* /usr/bin
echo '将docker.service 移到/etc/systemd/system/ 目录...'
cp -f ./docker.service /etc/systemd/system
echo '添加文件权限...'
chmod +x /etc/systemd/system/docker.service
echo '重新加载配置文件...'
systemctl daemon-reload
echo '启动docker...'
systemctl start docker
echo '设置开机自启...'
systemctl enable docker.service
if ! docker -v; then
echo "docker 安装失败..."
exit -1
fi
echo 'docker安装成功...'
#============ make docker-compose ===========
echo '安装docker-compose...'
cp -f ./docker-compose /usr/local/bin/
echo '添加文件执行权限...'
chmod +x /usr/local/bin/docker-compose
if ! docker-compose -v; then
echo "docker-compose 安装失败..."
exit -1
fi
echo 'docker-compose 安装成功...'

uninstall.sh文件(卸载脚本)

echo '删除docker所有容器'
docker stop $(docker ps -a -q)
docker rm $(docker ps -a -q)
echo '删除docker所有镜像'
docker rmi -f $(docker images -q)
echo '删除docker.service...'
rm -rf /etc/systemd/system/docker.service
echo '删除docker文件...'
rm -rf /usr/bin/docker*
echo '重新加载配置文件'
systemctl daemon-reload
echo '卸载成功...'

3、执行一键安装脚本:sh install.sh
一键安装docker及docker-compose_第5张图片
一键安装docker及docker-compose_第6张图片
4、验证:执行docker -v和 docker-compose -v查询版本
一键安装docker及docker-compose_第7张图片

你可能感兴趣的:(docker,容器,运维,linux)