Goal: Create an Nginx Image with Baked-In Hugo Content

We need an image that stops relying on the /config bind mount for the site content (/config/www) and instead has that content baked inside the image.

1. Identify Key Information from docker inspect

  • Base Image: lscr.io/linuxserver/nginx (This is where we start our new Dockerfile FROM).
  • User/Group IDs: PUID=99PGID=100. (This is crucial for file permissions).
  • Config Location: /config is where all configuration and the www folder live inside the running container.
  • Environment Variables: The image uses specific environment variables and an entrypoint script (/init) to manage file ownership and Nginx startup (S6_...LSIO...). We must keep this base image to leverage that automation.

2. The Dockerfile.Deploy

This file needs to be placed in the root of your Hugo repository on the machine where your CI/CD pipeline runs, after the hugo build command has created the ./public directory.

<em># Start from the SAME base image that your Unraid container uses</em>
FROM lscr.io/linuxserver/nginx

<em># We need to use the same PUID/PGID that the container runs with</em>
<em># (These can be hardcoded or passed as build arguments)</em>
ARG PUID=99
ARG PGID=100

<em># The base LinuxServer.io image expects content in /config/www</em>
<em># First, remove the default index.html provided by the base image</em>
RUN rm -rf /config/www/*

<em># Copy your built Hugo static files (which are in the local ./public directory)</em>
<em># into the correct location expected by the LinuxServer.io Nginx server (/config/www)</em>
COPY ./public /config/www

<em># Important: Use the 'chown' command to make sure the copied files are owned by the</em>
<em># user that the LinuxServer.io image expects to run as (PUID 99, PGID 100 in your case)</em>
RUN chown -R ${PUID}:${PGID} /config/www

3. How to Build and Deploy This

  1. In your CI/CD Pipeline: After the hugo build command runs, the next step builds this new image.bashdocker build -t myregistry/site-a:qa-latest . docker push myregistry/site-a:qa-latest Use code with caution.
  2. On Unraid Deployment (Addressing your previous question):You currently run the generic lscr.io/linuxserver/nginx image using your run command:bashdocker run ... 'lscr.io/linuxserver/nginx' Use code with caution.To deploy the new image with your content baked in, you stop using the generic image and run your custom image:bash<em># Stop the old container</em> docker stop nginx docker rm nginx <em># Run the NEW custom image instead of the generic LSIO image</em> docker run -d --name='nginx' ... 'myregistry/site-a:qa-latest' Use code with caution.

Note: When you switch to myregistry/site-a:qa-latest, the bind mount -v '/mnt/user/appdata/nginx':'/config':'rw' in your original docker run command is still useful for your existing Nginx configuration files, logs, and SSL keys, but the /config/www directory in that mount will now be ignored because the container image already has its own built-in /config/www content (which takes precedence over the directory in the bind mount if the base image handles it correctly, which LSIO images usually do).

Leave a Reply