start_nginx.sh

#!/bin/bash

LOGTIME=$(date "+%Y-%m-%d %H:%M:%S")
echo "[$LOGTIME] startup run..." >>/opt/sh/logs/start_nginx.log
nginx -c /etc/nginx/nginx.conf -g "daemon off;" >>/opt/sh/logs/start_nginx.log

vim /opt/sh/start_nginx.sh

docker cp /opt/sh/start_nginx.sh 9f953ea6f065:/opt/sh/start_nginx.sh

chmod +x /opt/sh/start_nginx.sh

6、将start_ssh.sh脚本添加到启动文件中

vim /root/.bashrc

7、在 .bashrc 文件末尾加入如下内容:

# startup run
if [ -f /opt/sh/start_nginx.sh ]; then
      . /opt/sh/start_nginx.sh
fi

6、将start_ssh.sh脚本添加到启动文件中

vim /root/.bashrc

7、在 .bashrc 文件末尾加入如下内容:

# startup run
if [ -f /opt/sh/start_nginx.sh ]; then
      . /opt/sh/start_nginx.sh
fi

8、保存后,等下次重启容器的时候,添加的服务也就跟着重启了。

复制文件到容器


docker cp /opt/sh 9f953ea6f065:/opt/sh

docker exec -itd 9f953ea6f065 /bin/bash 后台运行


docker exec -it 9f953ea6f065 /bin/bash

cd /opt/sh


docker cp /root/.bashrc 9f953ea6f065:/root/.bashrc

docker restart 9f953ea6f065

node -v
npm -v
文档更新时间: 2023-08-22 23:37   作者:admin