以while true使centos镜像启动,然后进入容器安装各种软件,最后保存容器为镜像?
pull镜像
docker pull centos:7.8.2003
生成一些文件
cat > Dockerfile <<'EOF'
FROM centos:7.8.2003
WORKDIR /home
COPY file ./
CMD ["sh","/home/startup.sh"]
EOF
cat > build.sh <<'EOF'
docker rm -f centos_dev0.1
docker rmi centos_dev:0.1
docker build -t centos_dev:0.1 .
EOF
cat > exec.sh <<'EOF'
docker exec -it centos_dev0.1 bash
EOF
cat > run.sh <<'EOF'
docker rm -f centos_dev0.1
docker run -d --name=centos_dev0.1 centos_dev:0.1
docker logs -f centos_dev0.1
EOF
mkdir file
#!/bin/sh
while true
do
date
sleep 5s
done
EOF
chmod +x *.sh
构建
./build.sh
run
./run.sh
进入容器
./exec.sh
安装软件(这里是java)
yum install -y java-1.8.0-openjdk
容器保存为镜像
docker commit centos_dev0.1 centos_dev:1.1
导出镜像(这样这个镜像里面就有java了)
docker save -o centos_dev.1.1.tar centos_dev:1.1
|