Install docker and docker-compose with one click

1. Create a directory for docker to store related files. This directory can be defined by yourself. Insert image description here2. Add relevant files and can extract them from the network disk. Among them, docker-20.10.9.tgz and docker-compose are installation packages, which can also be downloaded online as needed. Note that the docker-compose installation package needs to be renamed docker-compose after downloading .
Link: https://pan.baidu.com/s/1de98IS6tfxodagaAsJvsZQ
Extraction code: h4ta

Insert image description here
daemon.json file
Insert image description here

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

docker.service file
Insert image description here

[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 file (one-click installation script)
Insert image description here

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 file (uninstall script)

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. Execute the one-click installation script: sh install.sh
Insert image description here
Insert image description here
4. Verification: execute docker -v and docker-compose -v to query the version.
Insert image description here
Creation is not easy. Please help follow the official account. Thank you.
Insert image description here

Guess you like

Origin blog.csdn.net/qq_41060647/article/details/131568289