Setting Up Services

Docker

Docker Compose template

version: "3"

services:
  example:
    build: .
    image: author/example:tag
    container_name: example
    restart: always
    environment:
      - ENV_VAR=value
    ports:
      - 8000:80
    volumes:
      - /unnamed/volume/will/be/created
      - myvolume:/var/www/html
      - /srv/data/host/location:/srv/data
    networks:
      - mynetwork
    depends_on:
      - db
  db:
    image: postgres
    container_name: example-db
    restart: always
    expose:
      - 5432
    volumes:
      - example-db:/var/lib/postgresql/9.3./main

networks:
  mynetwork:

volumes:
  myvolume:
  example-db:

Nginx

Nginx templates

Static web page

The URL https://example.ert.space will point to files in /srv/www/example.ert.space.

server {
  listen 80;
  listen [::]:80;
  root /srv/www/example.ert.space;
  server_name example.ert.space;
  error_page 404 /404.html;
  location / {
    try_files $uri $uri/ =404;
  }
}

Reverse proxy

The URL https://example.ert.space will point to the local port 8080.

server {
  listen 80;
  listen [::]:80;
  server_name example.ert.space;
  location / {
    proxy_pass http://localhost:8080;
    proxy_set_header Host $host;
    proxy_set_header X-Real-IP $remote_addr;
  }
}

PHP site with HTTP authentication

The URL https://example.ert.space will point to the PHP application at /srv/www/example.ert.space/index.php. HTTP authentication done as indicated here.

server {
  listen 80;
  listen [::]:80;
  server_name example.ert.space;

  root /srv/www/example.ert.space;
  index index.html index.php;

  # set up HTTP basic authentication
  auth_basic           "Authentication Required";
  auth_basic_user_file /etc/apache2/.htpasswd;

  location / {
    try_files $uri $uri/ =404;
  }

  # process PHP requests
  location ~ \.php$ {
    include snippets/fastcgi-php.conf;
    fastcgi_pass unix:/run/php/php7.0-fpm.sock;
  }

  location ~ /\.ht {
    deny all;
  }
}