1

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?

Yogi Ghorecha
  • 1,584
  • 1
  • 19
  • 26
  • As you know this is how running containers looks like: Dockerfile > Build Image > Run Container. Outcome of single docker file will be one container,but you can use multi-step build to make it optimized. Here: https://docs.docker.com/develop/develop-images/multistage-build/ – Hassan Murtaza Sep 18 '19 at 10:49
  • Possible duplicate of [Docker: Combine multiple images](https://stackoverflow.com/questions/27214757/docker-combine-multiple-images) – David Maze Sep 18 '19 at 21:15

2 Answers2

5

move the . to the end

docker build -f httpd.Dockerfile -t mysinglecontainer:latest .

be sure to use the correct Dockerfile name also in your command the name is single-container.dockerfile

so the command is:

docker build -f single-container.dockerfile -t mysinglecontainer:latest .
LinPy
  • 16,987
  • 4
  • 43
  • 57
  • Yes, made the changes – Yogi Ghorecha Sep 18 '19 at 11:36
  • I run this command: docker build -f single-container.dockerfile -t mysinglecontainer:latest . it works fine but at the end I got this error: `Step 3/3 : COPY ./public-html/ /usr/local/apache2/htdocs/ COPY failed: stat /var/lib/docker/tmp/docker-builder162671660/public-html: no such file or directory` – Yogi Ghorecha Sep 18 '19 at 11:39
  • I am starting to think that you are missundertanding what multistage build do .......... – LinPy Sep 18 '19 at 11:46
  • This doesn't answer my questions. I need 1 container which has PHP & Apache both. and one single image with PHP & Apache when I run `docker images` I need only one image, after running above code, I have got 2 separate images for PHP & Apache. – Yogi Ghorecha Sep 18 '19 at 11:51
  • please understand first what multistage do, https://docs.docker.com/develop/develop-images/multistage-build/ . i was trying to help you get the concept . to run the both you need to install one of the service manually using dockerfile....... – LinPy Sep 18 '19 at 11:54
  • 1
    understand the document, and I found the solution, in single dockerfile, I called PHP & Apache & it worked. – Yogi Ghorecha Sep 19 '19 at 08:29
1

Found the solution

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

FROM php:7.2-fpm-alpine

LABEL maintainer="xxx@xxx.de" \
      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

Yogi Ghorecha
  • 1,584
  • 1
  • 19
  • 26