【发布时间】:2018-11-18 21:51:06
【问题描述】:
我已经开始学习 Docker。我有 Laravel 应用程序,想在 docker 容器中启动它。但我无法正确运行。
我有这个docker-compose.yml:
version: '2'
services:
# The Application
app:
build:
context: ./
dockerfile: app.dockerfile
working_dir: /var/www
volumes:
- ./:/var/www
environment:
- "DB_PORT=3306"
- "DB_HOST=database"
# The Web Server
web:
build:
context: ./
dockerfile: web.dockerfile
working_dir: /var/www
volumes_from:
- app
ports:
- 8080:80
# The Database
database:
image: mysql:5.6
volumes:
- dbdata:/var/lib/mysql
environment:
- "MYSQL_DATABASE=homestead"
- "MYSQL_USER=homestead"
- "MYSQL_PASSWORD=secret"
- "MYSQL_ROOT_PASSWORD=secret"
ports:
- "33061:3306"
volumes:
dbdata:
还有这个vhost.conf:
server {
listen 80;
index index.php index.html;
root /var/www/public;
location / {
try_files $uri /index.php?$args;
}
location ~ \.php$ {
fastcgi_split_path_info ^(.+\.php)(/.+)$;
fastcgi_pass app:9000;
fastcgi_index index.php;
include fastcgi_params;
fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
fastcgi_param PATH_INFO $fastcgi_path_info;
}
}
app.dockerfile:
FROM php:7.1.3-fpm
RUN apt-get update && apt-get install -y \
libmagickwand-dev --no-install-recommends \
libmcrypt-dev \
cron \
mysql-client \
vim \
&& docker-php-ext-install mcrypt pdo_mysql
web.docker 文件:
FROM nginx:1.10
ADD vhost.conf /etc/nginx/conf.d/default.conf
运行容器后,我有502 Bad Gateway,在网络容器中我有这个:
connect() failed (111: Connections refused) while connecting to upstream, client: 192.168.99.1, server: request "GET /HTTP/1.1", upstream: "fastcgi://172.19.0.3:9000", host: "192.168.99.101:8080".
我在服务器设置方面非常糟糕,不明白发生了什么。将非常感谢您的每一次帮助。
【问题讨论】:
-
我不知道到底是什么问题,但是您的 Web 容器无法连接到应用程序容器。您可以尝试从 Web 容器 ping 您的应用程序容器吗?
ping app。如果容器无法相互 ping 通,请尝试包含容器共享的网络。 -
我可以从
webping 到app。