McElfresh Blog

Go, PostgreSQL, MySQL, Ruby, Rails, Sinatra, etc.

Deploy Static Website to Fargate (Part 3)

Posted at — Nov 25, 2023

Create Our Site Docker Image

To create static files to serve in production, run

1$ hugo

and notice all the new static files that were generated in /public

Build our Nginx Container

1$ docker run -it <image id>
1$ docker cp <container name or image id>:/etc/nginx/conf.d/default.conf ~/
1$ docker exec -it <image name or id> sh
2$ cd /etc/nginx
1# under location / block:
2location /health {
3    access_log off;
4    return 200 'OK';
5}

Create this Dockerfile

 1# Dockerfile
 2
 3FROM nginx:alpine
 4
 5# Copy static site files to the Nginx document root
 6COPY ./public/. /usr/share/nginx/html
 7
 8# Copy custom nginx.conf with healthcheck to the container
 9COPY nginx.conf /etc/nginx/conf.d/default.conf
10
11# Expose port 80
12EXPOSE 80
13
14# Command to start Nginx
15CMD ["nginx", "-g", "daemon off;"]

Build our image. Note that we’re using buildx, and passing in a platform, because my Fargate setup expects x86 images, and I am building with a Mac Air M1:

docker buildx build –platform linux/amd64 -t ..

docker push