我想用Nginx,Mysql和PHP7对 ZendFramework2 应用程序进行Dockerize。
当我运行docker-compose up
时,所有容器都已构建完毕。但是,当我想访问localhost:8080
时,虽然default.conf
已由我的site.conf
替换,但我获得了nginx默认页面。重新启动nginx容器没有改变任何东西。
因为这是我第一次试用docker化应用程序,所以我也希望得到有关docker-setup的反馈
我关注this教程,但它最简单的形式也无效。
您可以使用我的Example Application重现此行为。
先谢谢你的帮助
搬运工-compose.yml
version: '2'
services:
db:
image: mysql:5.7
restart: always
volumes:
- db_data:/var/lib/mysql
environment:
MYSQL_ROOT_PASSWORD: ferienhof
MYSQL_DATABASE: ferienhof
MYSQL_USER: ferienhof
MYSQL_PASSWORD: ferienhof
web:
depends_on:
- db
image: nginx:latest
ports:
- "8080:80"
volumes:
- ./src:/code
- ./resources/site.conf:/etc/nginx/conf.d/default.conf
links:
- php
php:
build: .
volumes:
- ./src:/code
volumes:
db_data:
用于php的Dockerfile
php.ini取自github
FROM php:7.1-fpm
RUN apt-get update && apt-get install -y \
git \
cron \
libfreetype6-dev \
libicu-dev \
libjpeg62-turbo-dev \
libmcrypt-dev \
libpng12-dev \
libxslt1-dev
# Configure the gd library
RUN docker-php-ext-configure \
gd --with-freetype-dir=/usr/include/ --with-jpeg-dir=/usr/include/
# Install required PHP extensions
RUN docker-php-ext-install \
gd \
intl \
mbstring \
mcrypt \
pdo_mysql \
xsl \
zip \
soap
# Install the 2.4 version of xdebug that's compatible with php7
RUN pecl install -o -f xdebug-2.4.0
COPY resources/php.ini /usr/local/etc/php/
# Install composer and put binary into $PATH
RUN curl -sS https://getcomposer.org/installer | php \
&& mv composer.phar /usr/local/bin/ \
&& ln -s /usr/local/bin/composer.phar /usr/local/bin/composer
# Install phpunit and put binary into $PATH
RUN curl -sSLo phpunit.phar https://phar.phpunit.de/phpunit-old.phar \
&& chmod 755 phpunit.phar \
&& mv phpunit.phar /usr/local/bin/ \
&& ln -s /usr/local/bin/phpunit.phar /usr/local/bin/phpunit
# Install PHP Code sniffer
RUN curl -OL https://squizlabs.github.io/PHP_CodeSniffer/phpcs.phar \
&& chmod 755 phpcs.phar \
&& mv phpcs.phar /usr/local/bin/ \
&& ln -s /usr/local/bin/phpcs.phar /usr/local/bin/phpcs \
&& curl -OL https://squizlabs.github.io/PHP_CodeSniffer/phpcbf.phar \
&& chmod 755 phpcbf.phar \
&& mv phpcbf.phar /usr/local/bin/ \
&& ln -s /usr/local/bin/phpcbf.phar /usr/local/bin/phpcbf
资源/ site.conf
server {
server_name php-docker.local;
error_log /var/log/nginx/error.log;
access_log /var/log/nginx/access.log;
listen 80;
root /code/public;
location / {
index index.php;
try_files $uri $uri/ @php;
}
location @php {
# Pass the PHP requests to FastCGI server (php-fpm) on 127.0.0.1:9000
fastcgi_pass php:9000;
fastcgi_param SCRIPT_FILENAME /code/public/index.php;
include fastcgi_params;
}
}
答案 0 :(得分:0)
我改变了我的码头 - 组成了一点。工作文件可在http://git.schulz.codes/bootstrap/docker-php/tree/master
找到答案 1 :(得分:0)
您的nginx配置使用php-docker.local
作为server_name
,但您访问的网站名称为localhost
。