Search code examples
dockerdocker-composedockerfiledocker-swarmdocker-machine

How can I run TWO Docker images in a SINGLE Container?


I want to create a Single Docker Container with PHP Image & Apache Image, here is my dockerfile.

Docker File Name: single-container.dockerfile

# PHP image from docker hub
FROM php:7.2-cli


# Apache image from docker hub
FROM httpd:2.4

# public-html is path for my local codebase
COPY ./public-html/ /usr/local/apache2/htdocs/

In docker CLI when I run this command: docker build -f single-container.dockerfile . -t mysinglecontainer:latest

I'm getting below error.

enter image description here

Please advice, what are the changes needs to modify?


Solution

  • Found the solution

    Here is my Github URL: https://github.com/yogig/dockercron/

    FROM php:7.2-fpm-alpine
    
    LABEL maintainer="[email protected]" \
          muz.customer="xxx" \
          muz.product="xxx" \
          container.mode="development"
    
    #https://pkgs.alpinelinux.org/packages
    RUN apk add --no-cache --virtual .deps autoconf tzdata build-base libzip-dev mysql-dev gmp-dev \
                libxml2-dev libpng-dev zlib-dev freetype-dev jpeg-dev icu-dev openldap-dev libxslt-dev &&\
        docker-php-ext-install zip xml mbstring json intl gd pdo pdo_mysql iconv soap \
                               dom gmp fileinfo sockets bcmath mysqli ldap xsl &&\
        echo 'date.timezone="Europe/Berlin"' >> "${PHP_INI_DIR}"/php.ini &&\
        cp /usr/share/zoneinfo/Europe/Berlin /etc/localtime &&\
        echo 'Europe/Berlin' > /etc/timezone &&\
        curl -s https://www.phing.info/get/phing-latest.phar > /bin/phing &&\
        chmod a+x /bin/phing &&\
        ln -s /bin/phing /usr/local/bin/phing &&\
        ln -s /bin/phing /usr/local/phing &&\
        ln -s /bin/phing /usr/bin/phing &&\
        apk del .deps &&\
        apk add --no-cache libzip mysql libxml2 libpng zlib freetype jpeg icu gmp git subversion libxslt openldap \
                apache2 apache2-ldap apache2-proxy libreoffice openjdk11-jre ghostscript msttcorefonts-installer \
                terminus-font ghostscript-fonts &&\
        ln -s /usr/lib/apache2 /usr/lib/apache2/modules &&\
        ln -s /usr/sbin/httpd /etc/init.d/httpd &&\
        update-ms-fonts
    
    # copy crontabs for root user
    COPY crontab.txt /etc/crontabs/root
    
    #https://github.com/docker-library/httpd/blob/3ebff8dadf1e38dbe694ea0b8f379f6b8bcd993e/2.4/alpine/httpd-foreground
    #https://github.com/docker-library/php/blob/master/7.2/alpine3.10/fpm/Dockerfile
    CMD ["/bin/sh", "-c", "rm -f /usr/local/apache2/logs/httpd.pid && httpd -DBACKGROUND && php-fpm"]

    will install PHP Alpine image

    (1) FROM php:7.2-fpm-alpine
    

    Configuration for Apache

    (2) apk add --no-cache libzip mysql libxml2 libpng zlib freetype jpeg icu gmp git subversion libxslt openldap \
                apache2 apache2-ldap apache2-proxy libreoffice openjdk11-jre ghostscript msttcorefonts-installer \
                terminus-font ghostscript-fonts
    

    Last: In Docker CLI, I run the command docker-compose up and now in my Single Container, both PHP & Apache is running successfully.

    Note: To see content of docker-compose.yaml file, visit https://github.com/yogig/dockercron