Home > Mobile >  Docker nginx slim
Docker nginx slim

Time:03-04

I'm a new user of Docker. What I want to do is to setup (on my Windows PC) the Docker platform with a nginx server and a slim framework on this server, so that I be able to "host" a simple "hello world" page. My question is: should I create a container containing the Nginx and inside that container install the Slim framework? Or should i create two different containers (one for Nginx, one for Slim). And if so, how those two communicate?

Anyway whatever the solution is, first I would like to understand the "architecture" of this "build" and after that how to do it.

Thanks in advance

CodePudding user response:

You can use two containers, using docker-compose to connect slim and nginx, something like this:

docker-compose.yaml

version: "3.8"

services:
  php:
    container_name: slim
    build:
      context: ./docker/php
    ports:
      - '9000:9000'
    volumes:
      - .:/var/www/slim_app

  nginx:
    container_name: nginx
    image: nginx:stable-alpine
    ports:
      - '80:80'
    volumes:
      - .:/var/www/slim_app
      - ./docker/nginx/default.conf:/etc/nginx/conf.d/default.conf
    depends_on:
      - php

DOCKERFILE in ./docker/php

FROM php:7.4-fpm

RUN docker-php-ext-install ALL_YOUR EXTENSIONS

WORKDIR /var/www/slim_app

RUN curl -sS https://getcomposer.org/installer | php -- --install-dir=/usr/local/bin --filename=composer

Docker nginx in /docker/nginx/default.conf

server {

    listen 80;
    index index.php;
    server_name localhost;
    root /var/www/slim_app/public;

    location / {
        try_files $uri /index.php$is_args$args;
    }

    location ~ ^/index\\.php(/|$) {
        fastcgi_pass php:9000;
        fastcgi_split_path_info ^(. \\.php)(/.*)$;        
        internal;
    }

    location ~ \\.php$ {
        return 404;
    }

}

Just execute the containers docker-compose up -d go to http://localhost/

  • Related