Need help with docker-compose file: Run kirby with docker-compose behind a reverse nginx proxy by jwilder

Hello guys,

I need some help: I am trying to let my Kirby code run on a subdomain with a simpel container and image. I have some big issues to get it up and running. I have a working nginx config provided by jwilder the popular nginx reverse proxy image: link to image

My Dockerfile looks like this (it is pretty much a copy from the cookbook, commented out what is related to apache since I am using nginx):

# Use offical ubuntu:20.04 image
FROM ubuntu:20.04

# Set timezone
ENV TZ=Europe/Berlin

# Set geographic area using above variable
# This is necessary, otherwise building the image doesn't work
RUN ln -snf /usr/share/zoneinfo/$TZ /etc/localtime && echo $TZ > /etc/timezone

# Remove annoying messages during package installation
ARG DEBIAN_FRONTEND=noninteractive

# Install packages: web server & PHP plus extensions
RUN apt-get update && apt-get install -y \
#  apache2 \
#  apache2-utils \
#  ca-certificates \
  php \
#  libapache2-mod-php \
  php-curl \
  php-dom \
  php-gd \
  php-intl \
  php-json \
  php-mbstring \
  php-xml \
  php-zip && \
  apt-get clean && rm -rf /var/lib/apt/lists/*

# Copy virtual host configuration from current path onto existing 000-default.conf
#COPY default.conf /etc/apache2/sites-available/000-default.conf

# Remove default content (existing index.html)
RUN rm /var/www/html/*

# Activate Apache modules headers & rewrite
#RUN a2enmod headers rewrite

# Change web server's user id to match local user, replace with your local user id
RUN usermod --uid 1000 www-data

# Tell container to listen to port 80 at runtime
EXPOSE 80

# Start Apache web server
#CMD [ "/usr/sbin/apache2ctl", "-DFOREGROUND" ]

docker-compose-yml

version: '3'
services:
  webserver:
    build: .
    image: image_name
    networks:
      - proxy-tier
    container_name: kirbyserver
    ports:
      - "8099:80"
    environment:
      - VIRTUAL_HOST=sub.domain.tld
      - VIRTUAL_ROOT=/var/www/html
      - VIRTUAL_NETWORK=nginx-proxy
      - LETSENCRYPT_HOST=sub.domain.tld
      - LETSENCRYPT_EMAIL=my@email.tld
    volumes:
      - /srv/www/production/sub.domain.tld:/var/www/html
    env_file:
      - ./id.env

networks:
  proxy-tier:
    external:
      name: nginxproxy_default

The id.env-file
USERID=1000

my root-user-id is 0 and I have read somewhere that in this case the id should be set to 1000. I have tried around many things in many days but without any luck. That is why I started this question. Any help is appreciated.

Thanks a lot!

Maybe you could give more details about what is running where (and on which port), e.g. is everything running on the same machine?

I am questioning myself, when you have disabled Apache webserver from the container with your Kirby installation, how is the site being served?

What is the rationale to use the proxy, is it because of network or SSL termination or whatever?

Hi and thank you for your answer.

As I have mentioned there is a fully working nginx server which is configered as a reverse proxy so that one machine can handle many different urls. This is in fact already working. The docker-compose for the nginx is 100% just normal code from the linked jwilder image, nothing special about it but I will post it anyway:

version: '2'

services:

  nginx-proxy:
    image: jwilder/nginx-proxy:alpine
    container_name: nginx-proxy
    ports:
      - "80:80"
      - "443:443"
    volumes:
      - "/etc/nginx/vhost.d"
      - "/usr/share/nginx/html"
      - "/var/run/docker.sock:/tmp/docker.sock:ro"
      - ./certs:/etc/nginx/certs:ro
      - ./letsencrypt-acme:/etc/acme.sh
      - ./max_upload.conf:/etc/nginx/conf.d/max_upload.conf:ro
    restart: always

  letsencrypt-nginx-proxy-companion:
    image: nginxproxy/acme-companion
    volumes:
      - "/var/run/docker.sock:/var/run/docker.sock:ro"
      - ./certs:/etc/nginx/certs:rw
      - ./letsencrypt-acme:/etc/acme.sh
    volumes_from:
      - "nginx-proxy"
    restart: always

I am now just trying to create a container in which I can let Kirby run. The nginx container will create the .conf file automatically so I just need a few lines for the docker-compose or the Dockerfile to actually get it to work. I am juts struggeling because the way I have posted my files it does not work. The container stops after a second.

Thank you. Any help to point me to a direction is appreciated.

Hm, it is still not clear to me what you are doing. At least I think the reason why your kirbyserver container immediatly stops is because you are not running anything in it.

Maybe you should be more detailed about your architecture, folder setup and files. I even do not understand your id.env file and your remarks about the UID of root because from what you have posted, you are not going to use it.

It is not clear to me what you have here. Is it a different machine somewhere on the same or another network or do you mean the docker container nginx-proxy? A reverse proxy is not needed just to handle many different URLs so there might be an other reason to use it?

To me disabling the apache server in the Dockerfile doesn’t make sense. You need a webserver to be able to run PHP and Kirby.