我试图通过使用stream明和docker来构build服务来学习微服务架构。 我有这样的文件夹结构
./ ./base_service ./base_service/base.docker ./user_service ./user_service/user.docker ./auth_service ./auth_service/auth.docker ./gateway.docker ./vhost.conf ./docker-compose.yml
每个服务目录是一个stream明应用程序这是什么是我的docker-compose.yml文件看起来像
version: '2' services: gateway: build: context: ./ dockerfile: web.docker volumes: - ./:/var/www ports: - "8080:80" links: - base_service - auth_service - user_service base_service: build: context: ./base_service dockerfile: base.docker volumes: - ./:/var/www links: - broker auth_service: build: context: ./auth_service dockerfile: auth.docker volumes: - ./:/var/www links: - broker user_service: build: context: ./user_service dockerfile: user.docker volumes: - ./:/var/www links: - broker broker: image: redis:3.0 ports: - "63791:6379"
gateway.docker
FROM nginx ADD ./vhost.conf /etc/nginx/conf.d/default.conf WORKDIR /var/www
我的vhost.conf用于nginx
server { listen 80; index index.php index.html; root /var/www/base_service/public; location / { try_files $uri /index.php?$args; } location ~ \.php$ { fastcgi_split_path_info ^(.+\.php)(/.+)$; fastcgi_pass base_service: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文件只是获取一个PHP7-fpm图像
FROM php:7-fpm RUN apt-get update && apt-get install -y libmcrypt-dev mysql-client \ && docker-php-ext-install mcrypt pdo_mysql WORKDIR /var/www
运行docker-compose up -d命令并导航到http://localhost:8080 ,我得到一个页面“File not found”。 这是我第一次尝试一个微服务架构,所以在整个设置的configuration方面有点超出我的深度,任何帮助或指导将不胜感激。
我有类似的问题,因为我试图模仿所述的事情: 在这里 。 最后,我发现问题是我必须将所有这些文件放在PROJECT ROOT中(而不是在其中创build一个项目!)。 在做出这些改变之后,我能够无懈可击地完成我的项目。 希望这也能帮助你。