如何在单个容器中运行两个Docker映像?

时间:2019-09-18 10:40:46

标签: docker docker-compose dockerfile docker-swarm docker-machine

我想用 PHP映像 Apache映像创建一个Docker容器,这是我的dockerfile。

Docker文件名: 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/

在docker CLI中,当我运行以下命令时:docker build -f single-container.dockerfile . -t mysinglecontainer:latest

  

我遇到了错误。

enter image description here

请告知,需要进行哪些更改?

2 个答案:

答案 0 :(得分:4)

.移至末尾

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

请确保在命令中也使用正确的Dockerfile名称,single-container.dockerfile

所以命令是:

docker build -f single-container.dockerfile -t mysinglecontainer:latest .

答案 1 :(得分:0)

找到了解决方案

  

这是我的Github网址: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"]

  

将安装PHP Alpine映像

(1) FROM php:7.2-fpm-alpine
  

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

最后:在Docker CLI中,我运行命令docker-compose up,现在在我的Single Container中,PHP和Apache均成功运行。

  

注意:要查看docker-compose.yaml文件的内容,请访问   https://github.com/yogig/dockercron

相关问题