简体   繁体   中英

Running laravel/lumen in Docker using docker-compose

I am learning about microservice architecture and I want to setup a simple lumen app to run inside 3 separate containers using docker-compose

  • web - this will run my nginx front server
  • app - this will run my php-fpm
  • database - this will run my mysql server

This is my 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.dockerfile

FROM nginx:alpine
ADD deploy/vhost.conf /etc/nginx/conf.d/default.conf

deploy/app.dockerfile

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;
    }
}

When I run docker-compse up I can see everything is running fine:

在此输入图像描述

在此输入图像描述

But when I visit http://127.0.0.1:8080 I get the This site can't be reached error in chrome.

I am on windows using Docker Toolbox, and my docker version is: Docker version 17.10.0-ce, build f4ffd25

Any ideas how to properly setup LEMP stack on docker to run a simple lumen app?

Docker Toolbox is an older solution for Docker on Windows and Mac. There is no local host proxy from containers (you cannot use localhost to get to container exposed ports).

With Docker Toolbox actually comes Docker Machine, which is running a virtual machine behind the scenes and this virtual machine has a IP address. You can get the IP address using:

docker-machine ip

Or:

docker-machine ip default

It will give you something like 192.168.88.100. You would then use this address to get to your exposed ports such as http://192.168.88.100:8080/ .

Alternatively, you could remove the Docker Machine using docker-machine rm , uninstall Docker Toolbox, and then install Docker for Windows instead which will allow you to access published container ports on localhost .

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM