我想知道是否可以使用Docker同时运行两个Laravel Lumen?所以我在单独的文件夹中创建了一个全新的Laravel和Lumen安装,所以我将使用Lumen作为API,我想知道是否可以仅使用一个容器来运行它们.
我已经尝试过改变端口,但仍然没有运气,Laravel运行平稳,但不是Lumen.
这些是文件,它们是相同的,但差异只是端口(我不知道我正在做什么是对的)
泊坞窗,compose.yml
version: '2'
services:
web:
build:
context: ./
dockerfile: web.dockerfile
volumes:
- ./:/var/www
ports:
- "8080:80"
links:
- app
app:
build:
context: ./
dockerfile: app.dockerfile
volumes:
- ./:/var/www
links:
- database
environment:
- "DB_PORT=3306"
- "DB_HOST=database"
database:
image: mysql:5.6
environment:
MYSQL_ROOT_PASSWORD: secret
MYSQL_DATABASE: dockerApp
ports:
- "33061:3306"
cache:
image: redis:3.0
ports:
- "63791:6379"
app.dockerfile
FROM php:7.1.19-fpm
RUN apt-get update && apt-get install -y libmcrypt-dev mysql-client \
&& docker-php-ext-install mcrypt pdo_mysql
WORKDIR /var/www
web.dockerfile
FROM nginx:1.10
ADD ./vhost.conf/ /etc/nginx/conf.d/default.conf
WORKDIR /var/www
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 ps
CONTAINER ID IMAGE COMMAND CREATED STATUS PORTS NAMES
33987802df30 test-restful-api_web "nginx -g 'daemon of…" 34 hours ago Up About a minute 80/tcp, 443/tcp, 0.0.0.0:32768->8001/tcp test-restful-api_web_1
7f4b767ff2af test-restful-api_app "docker-php-entrypoi…" 34 hours ago Up About a minute 9000/tcp test-restful-api_app_1
be0675a6804d redis:3.0 "docker-entrypoint.s…" 34 hours ago Up About a minute 6379/tcp, 0.0.0.0:63793->63792/tcp test-restful-api_cache_1
f0b5fe2db9a4 mysql:5.6 "docker-entrypoint.s…" 34 hours ago Up About a minute 3306/tcp, 0.0.0.0:33063->33062/tcp test-restful-api_database_1
bdb308c7288f test_web "nginx -g 'daemon of…" 34 hours ago Up About a minute 443/tcp, 0.0.0.0:8080->80/tcp test_web_1
a74a1b5c2ec7 test_app "docker-php-entrypoi…" 34 hours ago Up About a minute 9000/tcp test_app_1
690b553eae36 mysql:5.6 "docker-entrypoint.s…" 34 hours ago Up About a minute 0.0.0.0:33061->3306/tcp test_database_1
fc47a3a84484 redis:3.0 "docker-entrypoint.s…" 34 hours ago Up About a minute 0.0.0.0:63791->6379/tcp test_cache_1
我想要实现的目标
我想在托管test.com(主网站)和api.test.com(用于restful api)上做类似的东西,但是在我的机器上,我想运行它这样的东西(如果可能的话)
localhost:8080(网站)
localhost:8000/8001(restful api)
UPDATE
我只是对目录进行了更改,之后就像这样
all_project_folder
---- test // front end project folder which is using Laravel 5.8
-------- * bunch of laravel things
-------- web.dockerfile
-------- app.dockerfile
-------- vhost.conf
-------- docker-compose.yml
---- test-restful-api // restful api project folder which is using Lumen 5.8
-------- * bunch of laravel things
-------- web.dockerfile
-------- app.dockerfile
-------- vhost.conf
-------- docker-compose.yml
但是现在我已经把它改成了这个结构
all_project_folder
---- test // folder for grouping the api and frontend
-------- frontend // test frontend folder which is laravel
-------- * bunch of laravel things
------------ web.dockerfile
------------ app.dockerfile
------------ vhost.conf
-------- restful-api // test api folder which is lumen
------------ web.dockerfile
------------ app.dockerfile
------------ vhost.conf
-------- docker-compose.yml // now there's only 1 docker-compose file, and it's outside those 2 folders (and the project can be added something like backend)
那么现在如何使用版本3设置dockerfile?我已经尝试过阅读文档,但我仍然没有得到它,并且有多个示例彼此不同,所以我不确定应该使用哪一个. (对不起,我对这个服务器的东西很新)
docker-compose.yml我的最新方法返回错误错误:服务“web”使用未定义的网络“前端”
version: '3'
services:
web:
build:
context: ./
dockerfile: frontend/web.dockerfile
volumes:
- ./:/var/www
ports:
- "8080:80"
networks:
- frontend
- api
frontend:
build:
context: ./
dockerfile: frontend/app.dockerfile
volumes:
- ./:/var/www
networks:
- database
environment:
- "DB_PORT=3306"
- "DB_HOST=database"
api:
build:
context: ./
dockerfile: restful-api/app.dockerfile
volumes:
- ./:/var/www
networks:
- database
environment:
- "DB_PORT=3306"
- "DB_HOST=database"
database:
image: mysql:5.6
environment:
MYSQL_ROOT_PASSWORD: secret
MYSQL_DATABASE: dockerApp
ports:
- "33061:3306"
cache:
image: redis:3.0
ports:
- "63791:6379"
我刚刚将网络添加到我的docker-compose.yml中,但却得到了这个错误
ERROR: The Compose file ‘.\docker-compose.yml’ is invalid because:
Unsupported config option for services.networks: ‘frontend’
networks:
frontend:
driver: asisten-pajak-frontend
api:
driver: asisten-pajak-api
最佳答案 最后,我在试图了解docker几天后找到了答案,最后,我得到的答案是使用
Laradock,你可以按照
Laradock documentation进行多个项目/容器.