运行 laravel/lumen 在 Docker 中使用 docker-compose
Running laravel/lumen in Docker using docker-compose
我正在学习微服务架构,我想使用 docker-compose
在 3 个单独的容器中为 运行 设置一个简单的流明应用程序
- web - 这将 运行 我的 nginx 前端服务器
- app - 这将 运行 我的 php-fpm
- 数据库 - 这将 运行 我的 mysql 服务器
这是我的docker-compose.yml
version: '2'
services:
# The Web Server
web:
build:
context: ./
dockerfile: ./deploy/web.dockerfile
working_dir: /var/www
volumes_from:
- app
ports:
- 8080:80
depends_on:
- app
# The Application
app:
build:
context: ./
dockerfile: ./deploy/app.dockerfile
working_dir: /var/www
volumes:
- ./:/var/www
environment:
- "DB_PORT=3306"
- "DB_HOST=database"
# The Database
database:
image: mysql:5.7
volumes:
- dbdata:/var/lib/mysql
environment:
- "MYSQL_ROOT_PASSWORD=secret"
- "MYSQL_DATABASE=homestead"
- "MYSQL_USER=homestead"
ports:
- "33061:3306"
volumes:
dbdata:
deploy/web.docker文件
FROM nginx:alpine
ADD deploy/vhost.conf /etc/nginx/conf.d/default.conf
deploy/app.docker文件
FROM yavin/alpine-php-fpm:7.1
COPY deploy/php.ini /etc/php7/conf.d/50-setting.ini
COPY deploy/php-fpm.conf /etc/php7/php-fpm.conf
deploy/php.ini
max_execution_time=30
max_input_time=60
memory_limit=128M
post_max_size=256M
upload_max_filesize=256M
error_reporting=E_ALL & ~E_DEPRECATED
display_errors=On
date.timezone=Europe/London
deploy/php-fpm.conf
[www]
user = nobody
group = nobody
listen = [::]:9000
chdir = /var/www
pm = static
pm.max_children = 5
pm.start_servers = 2
pm.min_spare_servers = 1
pm.max_spare_servers = 3
catch_workers_output = Yes
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;
}
}
当我 运行 docker-compse up
我可以看到一切正常 运行ning 很好:
但是当我访问 http://127.0.0.1:8080 时,我在 chrome 中收到 This site can’t be reached
错误。
我在 windows 使用 Docker 工具箱,我的 docker 版本是:Docker version 17.10.0-ce, build f4ffd25
关于如何在 docker 上正确设置 LEMP 堆栈到 运行 一个简单的流明应用程序有什么想法吗?
Docker 工具箱是 Windows 和 Mac 上 Docker 的旧解决方案。没有来自容器的本地主机代理(您不能使用 localhost
访问容器暴露的端口)。
随着Docker工具箱其实自带了DockerMachine,也就是运行后台的一个虚拟机,这个虚拟机有一个IP地址。您可以使用以下方式获取 IP 地址:
docker-machine ip
或:
docker-machine ip default
它会给你类似 192.168.88.100 的信息。然后,您将使用此地址到达您公开的端口,例如 http://192.168.88.100:8080/.
或者,您可以使用 docker-machine rm
删除 Docker Machine,卸载 Docker 工具箱,然后为 [=26= 安装 Docker ] 相反,这将允许您访问 localhost
.
上发布的容器端口
我正在学习微服务架构,我想使用 docker-compose
- web - 这将 运行 我的 nginx 前端服务器
- app - 这将 运行 我的 php-fpm
- 数据库 - 这将 运行 我的 mysql 服务器
这是我的docker-compose.yml
version: '2'
services:
# The Web Server
web:
build:
context: ./
dockerfile: ./deploy/web.dockerfile
working_dir: /var/www
volumes_from:
- app
ports:
- 8080:80
depends_on:
- app
# The Application
app:
build:
context: ./
dockerfile: ./deploy/app.dockerfile
working_dir: /var/www
volumes:
- ./:/var/www
environment:
- "DB_PORT=3306"
- "DB_HOST=database"
# The Database
database:
image: mysql:5.7
volumes:
- dbdata:/var/lib/mysql
environment:
- "MYSQL_ROOT_PASSWORD=secret"
- "MYSQL_DATABASE=homestead"
- "MYSQL_USER=homestead"
ports:
- "33061:3306"
volumes:
dbdata:
deploy/web.docker文件
FROM nginx:alpine
ADD deploy/vhost.conf /etc/nginx/conf.d/default.conf
deploy/app.docker文件
FROM yavin/alpine-php-fpm:7.1
COPY deploy/php.ini /etc/php7/conf.d/50-setting.ini
COPY deploy/php-fpm.conf /etc/php7/php-fpm.conf
deploy/php.ini
max_execution_time=30
max_input_time=60
memory_limit=128M
post_max_size=256M
upload_max_filesize=256M
error_reporting=E_ALL & ~E_DEPRECATED
display_errors=On
date.timezone=Europe/London
deploy/php-fpm.conf
[www]
user = nobody
group = nobody
listen = [::]:9000
chdir = /var/www
pm = static
pm.max_children = 5
pm.start_servers = 2
pm.min_spare_servers = 1
pm.max_spare_servers = 3
catch_workers_output = Yes
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;
}
}
当我 运行 docker-compse up
我可以看到一切正常 运行ning 很好:
但是当我访问 http://127.0.0.1:8080 时,我在 chrome 中收到 This site can’t be reached
错误。
我在 windows 使用 Docker 工具箱,我的 docker 版本是:Docker version 17.10.0-ce, build f4ffd25
关于如何在 docker 上正确设置 LEMP 堆栈到 运行 一个简单的流明应用程序有什么想法吗?
Docker 工具箱是 Windows 和 Mac 上 Docker 的旧解决方案。没有来自容器的本地主机代理(您不能使用 localhost
访问容器暴露的端口)。
随着Docker工具箱其实自带了DockerMachine,也就是运行后台的一个虚拟机,这个虚拟机有一个IP地址。您可以使用以下方式获取 IP 地址:
docker-machine ip
或:
docker-machine ip default
它会给你类似 192.168.88.100 的信息。然后,您将使用此地址到达您公开的端口,例如 http://192.168.88.100:8080/.
或者,您可以使用 docker-machine rm
删除 Docker Machine,卸载 Docker 工具箱,然后为 [=26= 安装 Docker ] 相反,这将允许您访问 localhost
.