Dockerfile CMD 未在容器启动时运行 [英] Dockerfile CMD not running at container start

查看:48
本文介绍了Dockerfile CMD 未在容器启动时运行的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

所以我已经为一个项目编写了一个 Dockerfile,我已经定义了一个 CMD 来在启动容器时运行以引导应用程序.

So i've written a Dockerfile for a project, i've defined a CMD to run on starting the container to bootstrap the application.

Dockerfile 看起来像

The Dockerfile looks like

# create our mount folders and volumes
ENV MOUNTED_VOLUME_DIR=sites
RUN mkdir /$MOUNTED_VOLUME_DIR
ENV PATH=$MOUNTED_VOLUME_DIR/sbin:$MOUNTED_VOLUME_DIR/common/bin:$PATH
RUN chown -Rf www-data:www-data /$MOUNTED_VOLUME_DIR

# Mount folders
VOLUME ["/$MOUNTED_VOLUME_DIR/"]

# Expose Ports
EXPOSE 443

# add our environment variables to the server
ADD ./env /env

# Add entry point script
ADD ./start.sh /usr/bin/startContainer
RUN chmod 755 /usr/bin/startContainer

# define entrypoint command
CMD ["/bin/bash", "/usr/bin/startContainer"]

start.sh 脚本执行一些 git 工作,例如克隆正确的 repo、设置环境变量以及启动主管.

The start.sh script, does some git stuff like cloning the right repo, setting environment vars, as well as starting supervisor.

启动脚本以此开头

#!/bin/bash

now=$(date +"%T")
echo "Container Start Time : $now" >> /tmp/start.txt
/usr/bin/supervisord -n -c /etc/supervisord.conf

我像这样启动我的新容器

I start my new container like this

docker run -d -p expoPort:contPort -t -i -v /$MOUNTED_VOLUME_DIR/$PROJECT:/$MOUNTED_VOLUME_DIR $CONTAINER_ID /bin/bash

当我登录到容器时,我看到主管还没有启动,也没有 nginx 或 php5-fpm.从 startContainer 脚本设置时间戳的/tmp/start.txt 文件不存在,表明它从未在 Dockerfile 中运行过 CMD.

when i login to the container i see that supervisor hasn't been started, and neither has nginx or php5-fpm. the /tmp/start.txt file with a timestamp set from the startContainer script doesn't exist, showing its never ran the CMD in the Dockerfile.

任何解决此问题的提示都会很棒

Any hints on to get this fixed would be great

推荐答案

这个:

docker run -d -p expoPort:contPort -t -i -v /$MOUNTED_VOLUME_DIR/$PROJECT:/$MOUNTED_VOLUME_DIR $CONTAINER_ID /bin/bash

在实例化容器后说运行/bin/bash".例如.跳过CMD.

Says 'run /bin/bash' after instantiating the container. E.g. skip CMD.

试试这个:

docker run -d -p expoPort:contPort -t -i -v /$MOUNTED_VOLUME_DIR/$PROJECT:/$MOUNTED_VOLUME_DIR $CONTAINER_ID 

这篇关于Dockerfile CMD 未在容器启动时运行的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆