docker-compose build on jekyll and serve via nginx

2020-02-15 docker nginx jekyll

I am trying to set up a Docker application that will allow me to build a static site via jekyll and then serve it via Nginx. I feel like I'm really misunderstanding something with shared volumes. Jekyll builds the site and I need to make the generated site (located in the _site directory) accessible to Nginx.

docker-compose.yml

version: '3.3'

volumes:
  static:

services:

  jekyll:
    build:
      context: './'
      dockerfile: './.docker/jekyll/Dockerfile'
    volumes: 
      - static:/usr/src/app

  nginx:
    build: './.docker/nginx/'
    ports:
      - '80:80'
    volumes:
      - static:/var/www/html/public
    depends_on: 
      - jekyll

Jekyll Dockerfile

FROM jekyll/jekyll:3.4.3

WORKDIR /usr/src/app

COPY . .

RUN jekyll build --verbose

ADD _site /var/www/html/public

Nginx Dockerfile:

FROM nginx

# Remove default nginx configs.
RUN rm -f /etc/nginx/conf.d/*

COPY static.conf /etc/nginx/conf.d/static.conf

Nginx config:

server {
    listen 80;
    server_name localhost;
    index index.html;
    root /var/www/html/public;

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

Answers

Related