All Nginx configuration files are stored under /etc/nginx.
I use this Dockerfile for “static” images such as our proxies:
FROM nginx:latest
ARG working_env
ADD nginx.conf /etc/nginx/nginx.conf
ADD $working_env/conf.d /etc/nginx/conf.d
# Testing all configuration files
RUN nginx -t -c /etc/nginx/nginx.conf
EXPOSE 80 443
CMD ["nginx", "-c", "/etc/nginx/nginx.conf", "-g", "daemon off;"]
And then I use the -p :80 when I start the container.
To do the same with docker-compose I use the something like this:
version: "3.7"
services:
nginx:
image: nginx-proxy
ports:
- "8081:80"
volumes:
- type: bind
source: ./nginx/nginx.conf
target: /etc/nginx/nginx.conf
deploy:
replicas: 1
update_config:
parallelism: 1
delay: 10s
max_failure_ratio: 0.1
order: start-first
restart_policy:
condition: on-failure
placement:
constraints: [node.role == worker]
This will mount the config from the directory where my docker-compose.yml file is and into the running container. Perfect for testing different configurations.