Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Docker command fails during build, but succeeds while executed within running container

Tags:

docker

the command :

docker build -t nginx-ubuntu .  

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 

Fails at the last line (./configure ...)

If I remove the last line and run a bash in the container, and execute the last line manually, it works.

I would expect that whatever command runs successfully within a container should work when the command is appended in the Dockerfile (prefixed by RUN)

am I missing something ?

like image 686
Max L. Avatar asked Jul 26 '13 21:07

Max L.


People also ask

What happens when the command docker build is executed?

The build command is used to build an image from a Dockerfile, but the command has to be run in the same directory as the Dockerfile. When an image is built, the commands specified in the Dockerfile are executed. The operating system is installed​ along with all the packages required in the Docker container.

How do I keep the docker container running after command line?

Method 1: You can use the -t (pseudo-tty) docker parameter to keep the container running. Method 2: You can run the container directly passing the tail command via arguments as shown below. Method 3: Another method is to execute a sleep command to infinity.

What does T flag do with docker run?

The -t (or --tty) flag tells Docker to allocate a virtual terminal session within the container. This is commonly used with the -i (or --interactive) option, which keeps STDIN open even if running in detached mode (more about that later).

Does docker build execute CMD?

A Dockerfile can have many RUN steps that layer on top of one another to build the image. CMD is the command the container executes by default when you launch the built image. A Dockerfile will only use the final CMD defined. The CMD can be overridden when starting a container with docker run $image $other_command .


2 Answers

The pwd is not persistent across RUN commands. You need to cd and configure within the same RUN.

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 
like image 186
creack Avatar answered Oct 03 '22 22:10

creack


As an alternative to @creak's answer, you can change the default working directory in a Dockerfile with the WORKDIR command:

FROM ubuntu:12.10 # Run update & install together so that the docker cache doesn't # contain an out-of-date APT cache (leading to 404's when installing # packages) RUN apt-get update && DEBIAN_FRONTEND=noninteractive apt-get -y install libpcre3 libssl-dev libpcre3-dev wget zip gcc ADD http://nginx.org/download/nginx-1.4.1.tar.gz nginx-1.4.1.tar.gz RUN tar -zxf nginx-1.4.1.tar.gz RUN wget --no-check-certificate https://github.com/max-l/nginx_accept_language_module/archive/master.zip RUN unzip master WORKDIR 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 

This also affects the default directory when you use docker run (overridden by the -w switch).

like image 43
alanfalloon Avatar answered Oct 03 '22 22:10

alanfalloon