Centos7离线安装Docker和docker-compose

Centos7离线安装Docker和docker-compose

 

1.查看系统环境,内核版本3.10及以上

#cat /etc/redhat-release

C:\B6524CA5\FFE70576-4703-4A02-A74C-F16492A9CC1D.files\image001.png

#uname -r

计算机生成了可选文字:
troot@localhost 、 ] # u n e 
3 . 10 . 0 . 1160 . 15 . 2 . e17 . x86 64

2.准备docker安装包和安装脚本

Docker官方下载地址:https://download.docker.com/linux/static/stable/x86_64/

根据自己需要的版本进行下载,这里我选用最新的docker-20.10.9.tgz

3.docker安装脚本

创建install-docker.sh脚本:

#cd /opt/

#vi install-docker.sh

计算机生成了可选文字:
troot@localhost 、 ] # cd /opt/ 
[ root@localhost 
opt ] # 11 
total 0 
[ root@ 
opt ] # vi install-docker.sh 
localhost

#!/bin/sh

usage(){

echo "使用方法: $0 FILE_NAME_DOCKER_CE_TAR_GZ"

echo " $0 docker-20.10.5.tgz"

echo "Get docker-ce binary from: https://download.docker.com/linux/static/stable/x86_64/"

echo "eg: wget https://download.docker.com/linux/static/stable/x86_64/docker-20.10.5.tgz"

echo ""

}

SYSTEMDDIR=/usr/lib/systemd/system

SERVICEFILE=docker.service

DOCKERDIR=/usr/bin

DOCKERBIN=docker

SERVICENAME=docker

 

if [ $# -ne 1 ]; then

usage

exit 1

else

FILETARGZ="$1"

fi

 

if [ ! -f ${FILETARGZ} ]; then

echo "Docker binary tgz files does not exist, please check it"

echo "Get docker-ce binary from: https://download.docker.com/linux/static/stable/x86_64/"

echo "eg: wget https://download.docker.com/linux/static/stable/x86_64/docker-20.10.5.tgz"

exit 1

fi

 

echo "##unzip : tar xvpf ${FILETARGZ}"

tar xvpf ${FILETARGZ}

echo

 

echo "##binary : ${DOCKERBIN} copy to ${DOCKERDIR}"

cp -p ${DOCKERBIN}/* ${DOCKERDIR} >/dev/null 2>&1

which ${DOCKERBIN}

 

echo "##systemd service: ${SERVICEFILE}"

echo "##docker.service: create docker systemd file"

cat >${SYSTEMDDIR}/${SERVICEFILE} <<EOF

[Unit]

Description=Docker Application Container Engine

Documentation=http://docs.docker.com

After=network.target docker.socket

[Service]

Type=notify

EnvironmentFile=-/run/flannel/docker

WorkingDirectory=/usr/local/bin

ExecStart=/usr/bin/dockerd \

-H tcp://0.0.0.0:4243 \

-H unix:///var/run/docker.sock \

--selinux-enabled=false \

--log-opt max-size=1g

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=on-failure

[Install]

WantedBy=multi-user.target

EOF

 

echo ""

 

systemctl daemon-reload

echo "##Service status: ${SERVICENAME}"

systemctl status ${SERVICENAME}

echo "##Service restart: ${SERVICENAME}"

systemctl restart ${SERVICENAME}

echo "##Service status: ${SERVICENAME}"

systemctl status ${SERVICENAME}

 

echo "##Service enabled: ${SERVICENAME}"

systemctl enable ${SERVICENAME}

cat >/etc/docker/daemon.json <<EOF

{

"registry-mirrors": ["http://hub-mirror.c.163.com"]

}

EOF

swapoff -a

iptables -P FORWARD ACCEPT

sysctl --system

systemctl daemon-reload

systemctl restart docker.service

 

echo "## docker version"

docker version

 

授权install-docker.sh为可以执行脚本

#chmod +x install-docker.sh

4.下载好的docker包上传至/opt目录下

计算机生成了可选文字:
1 root root 63350495 ] an 
9 20 : 23 docker-2E).1E).9.tgz 
9 20 : 19 Install-docker .sh 
-rwxr-xr-x 1 root root 
2741 ] an

5.执行install-docker.sh脚本,进行安装docker

#./install-docker.sh docker-20.10.9.tgz

C:\B6524CA5\FFE70576-4703-4A02-A74C-F16492A9CC1D.files\image005.png

版本号打印

计算机生成了可选文字:
Server : Docker 
Engine: 
Vers 10n : 
API vers 10n : 
GO vers 10n : 
G It comm It : 
Built: 
OS/Arch : 
Experimental : 
containerd : 
Vers 10n : 
GItComm1t: 
runc: 
Vers 10n : 
GItCommzt: 
doc ker- In It : 
10n : 
GItCommzt: 
Engine - Community 
20 . 10 . 9 
1 . 41 (mInunum vers 10n 1 . 12 ) 
g01 . 16 . 8 
79ea9d3 
Mon Oct 4 16 : 07 : 30 2021 
11nux/amd64 
false 
VI . 4 . 11 
5b46e404f6b9f661a205e28d59C982d3634148f8 
1 . 0 . 2 
VI. 0 . 2 . 0 . g52b36a2d 
0 . 19 . 0 
de4ØadØ

安装成功

#docker --version

C:\B6524CA5\FFE70576-4703-4A02-A74C-F16492A9CC1D.files\image007.png

6.安装docker-compose

下载安装包:

https://github.com/docker/compose/releases

下滑到Assets,点击Show all 26 assets,下载如下版本

计算机生成了可选文字:
, Assets 
echecksums.txt 
$docker-compose-darwin-aarch64 
$docker-compose-darwin-aarch64.sha256 
$docker-compose-darwin-x86 64 
$docker-compose-darwin-x86 64 ha256 
$docker-compose-linux-aarch64 
$docker-compose-linux-aarch64.sha256 
$docker-compose-linux-armv6 
$docker-compose-linux-armv6.sha256 
$docker-compose-linux-armv7 
$docker-compose-linux-armv7.sha256 
$docker-compose-linux-ppc641e 
$docker-compose-linux-ppc641e.sha256 
$docker-compose-linux-riscv64 
$docker-compose-linux-riscv64.sha256 
$docker-compose-linux-s390x 
$docker-compose-linux-s390x.sha256 
$docker-compose-linux-x86 64 
$docker-compose-linux-x86 64 . sha256 
$docker-compose-windows-aarch64.exe 
$docker-compose-windows-aarch64.exe.sha256 
$docker-compose-windows-x86 64.exe 
$docker-compose-windows-x86 64 · exe ha256 
$LICENSE 
1 £ 3 KB 
47 , MB 
96 Bytes 
4 & 3 MB 
95 Bytes 
41 丐 MB 
95 Bytes 
4a4 MB 
93 Bytes 
4a4 MB 
93 Bytes 
41 , MB 
95 Bytes 
41 . 4 MB 
95 Bytes 
4i1 MB 
93 Bytes 
42 , MB 
9 Bytes 
101 Bytes 
43 乇 MB 
100 Bytes 
300 Bytes 
1 1 hours ago 
1 1 hours ago 
1 1 hours ago 
1 1 hours ago 
1 1 hours ago 
1 1 hours ago 
1 1 hours ago 
1 1 hours ago 
1 1 hours ago 
1 1 hours ago 
1 1 hours ago 
1 1 hours ago 
1 1 hours ago 
1 1 hours ago 
1 1 hours ago 
1 1 hours ago 
1 1 hours ago 
1 1 hours ago 
1 1 hours ago 
1 1 hours ago 
1 1 hours ago 
1 1 hours ago 
1 1 hours ago 
1 1 hours ago

7.将下载好的docker-compose-Linux-x86_64上传到 /usr/local/bin/目录下

#cd /usr/local/bin/

计算机生成了可选文字:
[ root@ 
localhost 
opt ] # cd /usr/local/bln/ 
troot@localhost 
bin)# 11 
total 43900 
1 root root 44953600 ] an 
9 20 : 44 docker-compose-11nux-x86 64

8.修改名称进行授权即可

#mv docker-compose-linux-x86_64 docker-compose

#chmod +x docker-compose

C:\B6524CA5\FFE70576-4703-4A02-A74C-F16492A9CC1D.files\image010.png

9.查看docker-compose版本号,安装完成

#docker-compose --version

C:\B6524CA5\FFE70576-4703-4A02-A74C-F16492A9CC1D.files\image011.png

posted @ 2023-02-07 15:03  金·天  阅读(1394)  评论(0编辑  收藏  举报