Nginx and php in a docker-compose

less than 1 minute read

Create a file default.conf:

server {
    index index.html;
    server_name php-docker.local;
    error_log  /var/log/nginx/error.log;
    access_log /var/log/nginx/access.log;
    root /code;
}

Create your docker-compose file :

web:
    image: nginx:latest
    container_name: "nginx"
    ports:
        - "8080:80"
    volumes:
        - ./code:/code
        - ./default.conf:/etc/nginx/conf.d/default.conf
    links:
        - php
php:
    image: php:7.3-fpm
    container_name: "php"
    volumes:
        - ./code:/code

Create a file ./code/index.html:

<!DOCTYPE html>
<html>
<head>
<title>Welcome !</title>
<style>
    body {
        width: 35em;
        margin: 0 auto;
        font-family: Tahoma, Verdana, Arial, sans-serif;
    }
</style>
</head>
<body>
<h1>Welcome braincoke!</h1>
<p>It works</p>
</body>
</html>

Then docker-compose up -d.