phusion / baseimage-docker

A minimal Ubuntu base image modified for Docker-friendliness
http://phusion.github.io/baseimage-docker/
MIT License
8.96k stars 1.09k forks source link

weird problem #56

Closed cordoval closed 10 years ago

cordoval commented 10 years ago

The dockerfile below crashes after I uncomment these 4 lines shown below in the docker file:

#RUN touch "/etc/php5/fpm/conf.d/20-mongo.ini"
#RUN touch "/etc/php5/cli/conf.d/20-mongo.ini"
#RUN echo "extension=mongo.so" >> /etc/php5/fpm/conf.d/20-mongo.ini
#RUN echo "extension=mongo.so" >> /etc/php5/cli/conf.d/20-mongo.ini

here:

FROM phusion/baseimage:0.9.9

ENV HOME /root

RUN /etc/my_init.d/00_regen_ssh_host_keys.sh

CMD ["/sbin/my_init"]

# Some Environment Variables
ENV    DEBIAN_FRONTEND noninteractive

# Nginx-PHP Installation
RUN apt-get update
RUN apt-get install -y vim curl wget build-essential python-software-properties
RUN add-apt-repository -y ppa:ondrej/php5
RUN add-apt-repository -y ppa:nginx/stable
RUN apt-get update
RUN apt-get install -y php-pear php5-dev php5-cli php5-fpm php5-mysql php5-pgsql \
            php5-sqlite php5-curl php5-gd php5-mcrypt php5-intl php5-imap php5-tidy
RUN yes '' | pecl install mongo
RUN touch "/etc/php5/fpm/conf.d/20-mongo.ini"
RUN touch "/etc/php5/cli/conf.d/20-mongo.ini"
RUN echo "extension=mongo.so" >> /etc/php5/fpm/conf.d/20-mongo.ini
RUN echo "extension=mongo.so" >> /etc/php5/cli/conf.d/20-mongo.ini

RUN sed -i "s/;date.timezone =.*/date.timezone = UTC/" /etc/php5/fpm/php.ini
RUN sed -i "s/;date.timezone =.*/date.timezone = UTC/" /etc/php5/cli/php.ini

RUN apt-get install -y nginx

RUN echo "daemon off;" >> /etc/nginx/nginx.conf
RUN sed -i -e "s/;daemonize\s*=\s*yes/daemonize = no/g" /etc/php5/fpm/php-fpm.conf
RUN sed -i "s/;cgi.fix_pathinfo=1/cgi.fix_pathinfo=0/" /etc/php5/fpm/php.ini

RUN mkdir           /var/www
ADD build/default   /etc/nginx/sites-available/default
RUN mkdir           /etc/service/nginx
ADD build/nginx.sh  /etc/service/nginx/run
RUN chmod +x        /etc/service/nginx/run
RUN mkdir           /etc/service/phpfpm
ADD build/phpfpm.sh /etc/service/phpfpm/run
RUN chmod +x        /etc/service/phpfpm/run

EXPOSE 80
EXPOSE 81
# End Nginx-PHP

RUN apt-get clean && rm -rf /var/lib/apt/lists/* /tmp/* /var/tmp/*

why when running such a container would crash? can someone please explain?

cordoval commented 10 years ago

:baby: /cc @deeky666 @asm89 could you (begging) please take a look? thanks!

deeky666 commented 10 years ago

@cordoval What exactly means "crash"? Can you provide any error output of the container startup?

cordoval commented 10 years ago

after i run the container it dies, and then i docker logs it and:

/usr/bin/python2: error while loading shared libraries: libz.so.1: cannot open shared object file: No such file or directory
deeky666 commented 10 years ago

Looks like the package zlib1g-dev is not installed. Trying installing that.

cordoval commented 10 years ago

how, is that sudo apt-get zlib1g-dev ?

i mean does that not come in with the utils?

deeky666 commented 10 years ago

RUN apt-get install -y zlib1g-dev

cordoval commented 10 years ago
deeky666 commented 10 years ago

I am not sure what those lines have to do with it really. TBH I don't have enough context on this issue. Just tried to build your Dockerfile manually on my machine and it does not work because I don't have the build directory. Not sure how to reproduce. However, if I uncomment those instructions that are related to the build directory, I can at least start a container successfully. What is the docker command you use to startup a container?

cordoval commented 10 years ago

@deeky666 use the folders here http://github.com/fideloper/docker-nginx-php it is the box i use but modify the dockerfile according to what i pasted above on the description

I clone the git repo above into a folder with the name below and run from one level up:

docker build --rm -t docker-nginx-php ./docker-nginx-php

Then inherit in an empty Dockerfile FROM this build and build that image too and then run it with:

docker run -p 80:80 -v $(pwd)/api:/var/www --name c-api -d api /sbin/my_init --enable-insecure-key
deeky666 commented 10 years ago

@cordoval using the repo you provided, modifying the Dockerfile to match yours, I don't get any errors when starting the container. Even with those 4 lines uncommented. Try rebuilding the image without cache docker build -t my-image --no-cache . and then start the container with docker run -it my-image (for testing purposes). Works perfectly for me.

deeky@localhost:~/docker-nginx-php$ docker run -it my-image
*** Running /etc/my_init.d/00_regen_ssh_host_keys.sh...
*** Running /etc/rc.local...
*** Booting runit daemon...
*** Runit started as PID 8
cordoval commented 10 years ago

docker ps -a does not show it crashes? i will try the --no-cache option

deeky666 commented 10 years ago

No the container is running until I stop it. And as you see I don't get your phyton error.

cordoval commented 10 years ago

are you using the vagrant box from the korean yangsung? for boot2docker?

deeky666 commented 10 years ago

No I use it natively on ubuntu. Are you using docker through boot2docker? Maybe that causes some issues?

cordoval commented 10 years ago

yes i am on a mac using vagrant from youngsang boot2docker, but i don't think that is the problem right?

deeky666 commented 10 years ago

I don't know to be honest. My collegue is on mac, too and was working with boot2docker but also encountered weird issues. Especially shared host mounts seem to be a problem. However I am really not sure what is causing your problem. Did rebuilding the image do any difference?

cordoval commented 10 years ago

no i now get a different problem when i move the expose lines at the very end after the apt-get

2014/04/24 10:32:44 exec: "/sbin/my_init": stat /sbin/my_init: no such file or directory

before building it without that change still gives the same error

cordoval commented 10 years ago

@deeky666 https://gist.github.com/cordoval/95555ddcac19a677b568

deeky666 commented 10 years ago

Please paste the command you use to start the container.

cordoval commented 10 years ago
docker run -p 80:80 -v $(pwd)/api:/var/www --name c-api -d api /sbin/my_init --enable-insecure-key
deeky666 commented 10 years ago

Are you sure api is the image you built before? Because in your Gist you built an image called docker-nginx-php. Otherwise I don't have a reasonable explanation for this. This is my startup (replaced -d with -it for debugging): https://gist.github.com/deeky666/0de216ed8bd7609191a8

cordoval commented 10 years ago

i build an image off of that, so

docker build --no-cache --rm -t api ./api

and the docker file inside that folder is:

# api server already running nginx
FROM docker-nginx-php

MAINTAINER Luis Cordova version: 1.0

EXPOSE 80
EXPOSE 81
deeky666 commented 10 years ago

hmm weird, reproduced with your second Dockerfile and still get no errors :(

cordoval commented 10 years ago

I can't believe it, i am rebuilding my vagrant box now. And retrying. What is your other friend using then in his mac now?

deeky666 commented 10 years ago

He switched to use docker natively in an ubuntu virtual machine directly without boot2docker. So no docker client -> vagrant -> docker daemon setup anymore.

cordoval commented 10 years ago

so here is the real question @deeky666 , it seems to work for you when you fire the run with -d and the argument is the direct build docker-nginx-php, however if you extend that into a folder api with a dockerfile with FROM docker-nginx-php and everything else empty and run the container with -d pointing to the new api image, it fails. So the notion of extending dockerfiles is what I am lacking and is not clear how to extend the dockerfiles in a way that keep them running.

Can you please explain how to extend dockerfiles?

deeky666 commented 10 years ago

What you have to do is the following:

  1. build the docker-nginx-php image from the root folder (as base for your api image)
  2. build the api image with the previously built image docker-nginx-php as base using the FROM instruction
  3. create anapi image container with the docker run command

Extending images is exactly that. You use the FROM instruction in your Dockerfile to tell docker to build additional instructions on top of that base image.

cd /path/to/docker-nginx-php
docker build -t docker-nginx-php .
cd api
docker build -t api .
docker run -p 80:80 -v $(pwd):/var/www --name c-api -d api /sbin/my_init --enable-insecure-key

Something like that.

cordoval commented 10 years ago

this is exactly what we are doing

now i tried and get

docker@boot2docker:/vagrant$ docker run -it -p 80:80 -v $(pwd)/api:/var/www --name c-api docker-nginx-php bash
bash: error while loading shared libraries: libtinfo.so.5: cannot open shared object file: No such file or directory

is messed up

deeky666 commented 10 years ago

WTH! There is something seriously broken in your image if you can't even get bash to run oO. Maybe your Dockerfile is messed up. I would advise you to build the image step by step from "scratch". Each time running a container and see what happens. Then add another instruction and run again until you get an error.

cordoval commented 10 years ago

@deeky666 can you push your dockerfile into a repo? so i can clone and verify?

I went to my old ubuntu machine and i get the same problem

deeky666 commented 10 years ago

It's basically what you pasted for me. Here are the two Dockerfiles:

https://gist.github.com/deeky666/657ff5832670beb630b3

cordoval commented 10 years ago

your gist is wrong is not from phusion only and it is not using an extra docker file anymore

cordoval commented 10 years ago

will the fact that the exposes come after the last line or before the apt-get clean matter?

deeky666 commented 10 years ago

yeah sorry. replace phusion with docker-nginx-php. I was just naming it like that on my machine. No it does not matter where you put the EXPOSE instructions

cordoval commented 10 years ago

i have no idea stumped

deeky666 commented 10 years ago

Hmmm is the original docker-nginx-php image running for you fine? Without modifications?

cordoval commented 10 years ago

so i removed the api dockerfile and just running it from docker-nginx-php on the run, the build for docker-nginx-php works however I added a line like i show in my gist, it is not the clone straight. It has only those modifications on the dockerfile. The run is what crashes.

deeky666 commented 10 years ago

Try building and running the original Dockefile, if that runs fine please outline the modified lines again. Then we'll see.

cordoval commented 10 years ago

solved it by removing the exposes