所以我为一个项目编写了一个Dockerfile,我已经定义了一个CMD来启动容器以运行应用程序.
Dockerfile看起来像
# 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,设置环境变量,以及启动主管.
启动脚本以此开头
#!/bin/bash now=$(date +"%T") echo "Container Start Time : $now" >> /tmp/start.txt /usr/bin/supervisord -n -c /etc/supervisord.conf
我像这样开始我的新容器
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.
任何有关修复此问题的提示都会很棒
这个:
docker run -d -p expoPort:contPort -t -i -v /$MOUNTED_VOLUME_DIR/$PROJECT:/$MOUNTED_VOLUME_DIR $CONTAINER_ID /bin/bash
在实例化容器之后说’run / bin / bash’.例如.跳过CMD.
试试这个:
docker run -d -p expoPort:contPort -t -i -v /$MOUNTED_VOLUME_DIR/$PROJECT:/$MOUNTED_VOLUME_DIR $CONTAINER_ID