0

I am trying to setup an NGINX server and mount a directory to the container. I have a DigitalOcean server running, and want to link my website data into the nginx container.

Part of the docker file is:

webserver:
        depends_on: 
            - wordpress
        image: nginx:latest
        container_name: webserver
        restart: unless-stopped
        # Expose port 80 to enable the config options defined nginx.conf
        ports:
            - "80:80"
            - "443:443"
        # combiation of named volumes and bind mounts
        # bind wordpress app code 
        # bind nginx config dir on host
        # mount certbot certificates and keys for domain
        volumes:
            - wp_data:/var/www/html
            - ~/custom:/etc/nginx/conf.d/custom
            - ./nginx-conf:/etc/nginx/conf.d
            - certbot-etc:/etc/letsencrypt
        networks:
            - kgNetwork
        command: /bin/bash -c "envsubst < /etc/nginx/conf.d/custom > /etc/nginx/conf.d/default.conf && exec nginx -g 'daemon off;'"

nginx.conf

server {

    # Tells ngxinx to listen on port 80
    listen 80;
    listen [::]:80;

    root /usr/share/nginx/html;
    index index.html index.htm;

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

the container starts but I don't see my linked test html file. the log shows: envsubst: error while reading "standard input": Is a directory

I am not quite sure how to understand this. On my server I created in my home folder the subfolder "custom" containing an index.html.

My thought process so far was:

  1. Create a custom html in the host folder
  2. Mount the volume via ~/custom:/etc/nginx/conf.d/custom
  3. Run the command: /bin/bash -c "envsubst < /etc/nginx/conf.d/custom > /etc/nginx/conf.d/default.conf && exec nginx -g 'daemon off;'"to setup the custom website on nginx.

The nginx container is running but loading the site does not show anything. I am new to docker and tried to debug for 2hrs now but I am clearly missing the point :)

Thanks Sebastian

0

1 Answer 1

1

You say you created $HOME/custom/index.html. When you launch the container, you do it with a bind mount ~/custom:/etc/nginx/conf.d/custom; that mounts the directory $HOME/custom into the nginx configuration directory. When you then try to run envsubst, its input is the custom directory, which leads to the error you get.

If that directory actually contains the HTML files, you need to mount it on the location you specified in your configuration

volumes:
  - ~/custom:/usr/share/nginx/html

If you're trying to do environment-variable substitution on the HTML content at deploy time, you also need to change the path in the envsubst command. Consider using a Docker entrypoint wrapper script to do this templating. Also remember that writes into the mounted directory after container startup are bidirectional, so with this setup you might have trouble running multiple containers off the same (shared) host content.

Sign up to request clarification or add additional context in comments.

1 Comment

Thank you for the fast answer, but I can honestly not yet follow everything to the fullest you tell me :) Apologies. So in order to "start" simple I took out the statement mentioned above and just mounted ~/custom:/usr/share/nginx/html Then I use sudo docker container exec -it webserver bash and went into the usr/share/nginx/html folder, which is empty. so I wonder, why the mount has not worked then, even though my host folder has an index.html?