本文介绍了Docker命令在构建期间失败,但在运行容器中执行时成功的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
命令:
docker build -t nginx-ubuntu .
下面的Dockerfile:
whith the Dockerfile below :
FROM ubuntu:12.10
RUN apt-get update
RUN apt-get -y install libpcre3 libssl-dev
RUN apt-get -y install libpcre3-dev
RUN apt-get -y install wget zip gcc
RUN wget http://nginx.org/download/nginx-1.4.1.tar.gz
RUN gunzip nginx-1.4.1.tar.gz
RUN tar -xf nginx-1.4.1.tar
RUN wget --no-check-certificate https://github.com/max-l/nginx_accept_language_module/archive/master.zip
RUN unzip master
RUN cd nginx-1.4.1
RUN ./configure --add-module=../nginx_accept_language_module-master --with-http_ssl_module --with-pcre=/lib/x86_64-linux-gnu --with-openssl=/usr/lib/x86_64-linux-gnu
最后一行失败./configure ...)
Fails at the last line (./configure ...)
如果我删除最后一行并在容器中运行bash,并且
手动执行最后一行,它将工作。
If I remove the last line and run a bash in the container, andexecute the last line manually, it works.
我会期望无论什么命令在一个cont内成功运行ainer应该工作
当命令附加在Dockerfile(以RUN为前缀)
I would expect that whatever command runs successfully within a container should workwhen the command is appended in the Dockerfile (prefixed by RUN)
我是否缺少某些东西?
am I missing something ?
推荐答案
pwd在RUN命令之间不持久。您需要在同一个RUN中进行cd和配置。
The pwd is not persistent across RUN commands. You need to cd and configure within the same RUN.
此Dockerfile正常工作:
This Dockerfile works fine:
FROM ubuntu:12.10
RUN apt-get update
RUN apt-get -y install libpcre3 libssl-dev
RUN apt-get -y install libpcre3-dev
RUN apt-get -y install wget zip gcc
RUN wget http://nginx.org/download/nginx-1.4.1.tar.gz
RUN gunzip nginx-1.4.1.tar.gz
RUN tar -xf nginx-1.4.1.tar
RUN wget --no-check-certificate https://github.com/max-l/nginx_accept_language_module/archive/master.zip
RUN unzip master
RUN cd nginx-1.4.1 && ./configure --add-module=../nginx_accept_language_module-master --with-http_ssl_module --with-pcre=/lib/x86_64-linux-gnu --with-openssl=/usr/lib/x86_64-linux-gnu
这篇关于Docker命令在构建期间失败,但在运行容器中执行时成功的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!