我需要在 Docker 容器中启动一个后台作业(Google SQL Proxy),实际上它是一个 AppEngine 镜像。
在尝试启动后台作业时,我遇到了一些问题。我发现,要么在运行脚本的 RUN 命令中分离容器后立即丢弃了作业,要么容器停止正常工作(请参见 CMD 命令在脚本中的用法)。
以下是 Dockerfile 的内容:
FROM eu.gcr.io/google-appengine/ubuntu-php56
ADD ./run.sh /app
RUN chmod 777 /app/run.sh
#RUN nohup /app/run.sh & #This is lost the moment I finished creation of container
CMD nohup /app/run.sh & #This crash the container
这是run.sh文件:
#!/bin/bash
while true
do
echo "Beep"
sleep 2
done
这里是构建Docker镜像的命令:
docker image build --tag red .
以下是创建Docker容器的命令:
docker run -d -p 8080:8080 --name red1 red
以下是我连接容器以查看其中内容的方法:
docker exec -it red1 /bin/bash
我的目标是能够启动并长时间运行run.sh脚本。