Multiple dependent ? Dockerfiles building a LAMP container

I’m trying to build a LAMP container and I have already built several containers: httpd 2.4.23, redis 3.0.7, mysql 5.6.30 by compiling them myself from source code downloaded archives. I have based all of these above on the debian container.

Now that I’m doing the php 5.6.20 container it complains that it does not know about apache and mysql.

  • Exposing ports in Docker won't work
  • Cannot produce message to kafka from service running in docker
  • How to extend an existing docker image?
  • Error using akka remoting with artery over docker instances
  • JGroups doesnt form a cluster while running inside docker across multiple nodes
  • Can't access env variables in RUN script.sh Dockerfile
  • Here is the Dockerfile for the php container:

    FROM debian
    
    RUN apt-get update
    RUN apt-get install -y build-essential;
    RUN apt-get install -y cmake;
    RUN apt-get install -y libfreetype6-dev libjpeg-dev libpng12-dev libcurl4-openssl-dev libbz2-dev libxml2-dev libxslt-dev libgd2-xpm-dev php5-imap libz-dev
    
    WORKDIR /usr/bin/
    COPY php-5.6.20.tar.gz /usr/bin/
    RUN gzip -d php-5.6.20.tar.gz
    RUN tar -xvf php-5.6.20.tar
    RUN ln -s php-5.6.20 php
    
    WORKDIR /usr/bin/php/
    RUN ./configure \
      --prefix=/usr/bin/ \
      --with-apxs2=/usr/bin/apache/bin/apxs \
      --with-config-file-path=/usr/bin/php-5.6.20/ \
      --enable-libgcc \
      --with-mysqli=/usr/bin/mysql/mysql_config \
      --with-zlib-dir=/usr \
      --with-jpeg-dir=/usr \
      --with-png-dir=/usr \
      --with-gd \
      --enable-gd-native-ttf \
      --with-freetype-dir=/usr \
      --enable-ftp \
      --enable-xml \
      --enable-zip \
      --with-bz2 \
      --enable-wddx \
      --without-pear \
      --enable-mbstring \
      --with-curl
    
    RUN make
    
    RUN make install
    

    I wonder if I should base it instead on: FROM httpd:2.4.23. But then I would need to base httpd on the mysql one, and / or on the redis one… I don’t really like that setup.

    I have also installed Docker Compose but I wonder if it could be helpful in my situation.

    UPDATE: Here is the fully working Dockerfile

    FROM debian
    
    RUN apt-get update
    RUN apt-get install -y build-essential;
    RUN apt-get install -y cmake;
    RUN apt-get install -y openssl libssl-dev;
    RUN apt-get install -y libpcre3 libpcre3-dev
    
    WORKDIR /usr/bin/
    COPY httpd-2.4.23.tar.gz /usr/bin/
    RUN gzip -d httpd-2.4.23.tar.gz
    RUN tar -xvf httpd-2.4.23.tar
    RUN ln -s httpd-2.4.23 httpd
    COPY apr-1.5.2.tar.gz /usr/bin/httpd/srclib/
    COPY apr-util-1.5.4.tar.gz /usr/bin/httpd/srclib/
    WORKDIR /usr/bin/httpd/srclib/
    RUN gzip -d apr-1.5.2.tar.gz
    RUN gzip -d apr-util-1.5.4.tar.gz
    RUN tar -xvf apr-1.5.2.tar
    RUN tar -xvf apr-util-1.5.4.tar
    RUN ln -s apr-1.5.2 apr;
    RUN ln -s apr-util-1.5.4 apr-util
    
    WORKDIR /usr/bin/httpd/
    RUN ./configure \
      --prefix=/usr/bin/apache \
      --enable-rewrite \
      --enable-deflate \
      --enable-ssl
    
    RUN make
    
    RUN make install
    
    RUN apt-get update
    RUN apt-get install -y libncurses-dev
    
    COPY mysql-5.6.30.tar.gz /usr/bin/
    WORKDIR /usr/bin/
    RUN gzip -d mysql-5.6.30.tar.gz
    RUN tar -xvf mysql-5.6.30.tar
    RUN ln -s mysql-5.6.30 mysql
    
    WORKDIR /usr/bin/mysql/
    RUN mkdir install; mkdir install/data; mkdir install/var; mkdir install/etc; mkdir install/tmp
    
    RUN cd /usr/bin/mysql/; cmake \
      -DCMAKE_INSTALL_PREFIX=/usr/bin/mysql/install \
      -DWITH_INNOBASE_STORAGE_ENGINE=1 \
      -DMYSQL_DATADIR=/usr/bin/mysql/install/data \
      -DDOWNLOAD_BOOST=1 \
      -DWITH_BOOST=/usr/bin/mysql/install/boost \
      -DMYSQL_UNIX_ADDR=/usr/bin/mysql/install/tmp/mysql.sock
    
    RUN make
    
    RUN make install
    
    RUN apt-get update
    RUN apt-get install -y libfreetype6-dev libjpeg-dev libpng12-dev libcurl4-openssl-dev libbz2-dev libxml2-dev libxslt-dev libgd2-xpm-dev php5-imap libz-dev
    
    WORKDIR /usr/bin/
    COPY php-5.6.20.tar.gz /usr/bin/
    RUN gzip -d php-5.6.20.tar.gz
    RUN tar -xvf php-5.6.20.tar
    RUN ln -s php-5.6.20 php
    
    WORKDIR /usr/bin/php/
    RUN ./configure \
      --prefix=/usr/bin/php \
      --with-apxs2=/usr/bin/apache/bin/apxs \
      --with-config-file-path=/usr/bin/php-5.6.20/ \
      --enable-libgcc \
      --with-mysqli=/usr/bin/mysql/install/bin/mysql_config \
      --with-zlib-dir=/usr \
      --with-jpeg-dir=/usr \
      --with-png-dir=/usr \
      --with-gd \
      --enable-gd-native-ttf \
      --with-freetype-dir=/usr \
      --enable-ftp \
      --enable-xml \
      --enable-zip \
      --with-bz2 \
      --enable-wddx \
      --without-pear \
      --enable-mbstring \
      --with-openssl
      --with-curl
    
    RUN make
    
    RUN make install
    
    ENTRYPOINT ["/usr/bin/apache/bin/apachectl", "start", "-D FOREGROUND"]
    
    EXPOSE 80
    
    # Build the container: docker build -t stephaneeybert/httpd:2.4.23 .
    # Run the container: docker run -d -p 127.0.0.1:80:80 --name httpd stephaneeybert/httpd:2.4.23
    # Check that the port is open: nmap -p 8081 localhost
    

  • Installing docker on Ubuntu 16.10
  • Install pgAdmin 3 without postgresql
  • Docker flask uwsgi 404 on a remote host
  • How to assign specific IP to container and make that accessible outside of VM host?
  • Symfony app/console command is not running with cronjob inside Docker container
  • Docker: reload a nodejs app with nodemon
  • One Solution collect form web for “Multiple dependent ? Dockerfiles building a LAMP container”

    If you need apache running in your container, you can install apache in your image with above Dockerfile, just as the same as you install the build-essential stuffs. Which means:

    RUN apt-get install -y apache2
    

    or similar command. If you also need the configure for this apache application, you can use ADD or COPY command to add your configure file from outside to inside of your container. More details can be found here.

    If you need apache as an independent container, you can use docker-compse to achieve it. Start apache in another container, then use depends_on to config the dependency between your containers. You may use ports to change the port number of each container, so they can communicate between each other.

    Docker will be the best open platform for developers and sysadmins to build, ship, and run distributed applications.