Docker离线安装

服务器系统在线安装Docker源可能有点问题,遂采用离线安装的方式

Docker安装包下载地址:点这里

1.选择一个版本下载压缩包并上传服务器进行解压

 tar -zxf docker-20.10.7.tgz 

2.然后将docker服务注册为service

cp docker/* /usr/bin/
vim /etc/systemd/system/docker.service
[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
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

3.给予可执行权限

chmod +x /etc/systemd/system/docker.service

4.重载unit配置

systemctl daemon-reload  

5.启动Docker并设置开机自启

systemctl start docker && systemctl enable docker.service 

6.查看docker状态

systemctl status docker 

查看系统版本

cat /etc/.productinfo

Kylin Linux Advanced Server
release V10 (SP1) /(Tercel)-x86_64-Build20/20210518

1.创建目录并定义两个变量

mkdir /kylinos
export linux_root=/kylinos
export rpm_repo=http://update.cs2c.com.cn:8080/NS/V10/V10SP1.1/os/adv/lic/base/

2.把一些常用的命令包安装到上面创建的目录下,自动把依赖包都安装

yum -y --installroot=${linux_root} install yum iputils iproute procps-ng

3.复制一个本地的shell环境配置

cp /etc/skel/.bash*  /kylinos/root

4.测试一下

chroot ${linux_root} /bin/bash

5.退出上面切入的shell环境,打包目录为镜像

exit
tar -C ${linux_root} -c . | docker import - kylinos base:v1.0

6.查看镜像

docker images

7.运行容器

docker run -it 6151671d5e88 bash