Skip to content

Instantly share code, notes, and snippets.

@pganssle
Last active August 21, 2021 15:33
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save pganssle/31a899ea34d2ecff77034b25e077b600 to your computer and use it in GitHub Desktop.
Save pganssle/31a899ea34d2ecff77034b25e077b600 to your computer and use it in GitHub Desktop.
worker_processes auto;
events {
worker_connections 4096;
}
http {
server {
listen [::]:80 default_server;
listen *:80 default_server;
root /var/www;
location / {
try_files $uri $uri/ = 404;
}
}
}
version: '3'
services:
"nginx":
image: "nginx:latest"
restart: "unless-stopped"
volumes:
- "./config/nginx:/etc/nginx"
- "./data/www:/var/www"
ports:
- "80:80"
expose:
- "80"
command: "nginx"

Works in the container:

$ sudo docker-compose run --rm nginx bash -c 'nginx && curl localhost'
Creating tmppkmps4k6s5_nginx_run ... done
127.0.0.1 - - [21/Aug/2021:15:24:02 +0000] "GET / HTTP/1.1" 200 3 "-" "curl/7.64.0"
Hi

Can't be reached from outside the docker container:

$ sudo docker-compose up nginx
Creating network "tmppkmps4k6s5_default" with the default driver
Creating tmppkmps4k6s5_nginx_1 ... done
Attaching to tmppkmps4k6s5_nginx_1
nginx_1  | /docker-entrypoint.sh: /docker-entrypoint.d/ is not empty, will attempt to perform configuration
nginx_1  | /docker-entrypoint.sh: Looking for shell scripts in /docker-entrypoint.d/
nginx_1  | /docker-entrypoint.sh: Launching /docker-entrypoint.d/10-listen-on-ipv6-by-default.sh
nginx_1  | 10-listen-on-ipv6-by-default.sh: info: /etc/nginx/conf.d/default.conf is not a file or does not exist
nginx_1  | /docker-entrypoint.sh: Launching /docker-entrypoint.d/20-envsubst-on-templates.sh
nginx_1  | /docker-entrypoint.sh: Launching /docker-entrypoint.d/30-tune-worker-processes.sh
nginx_1  | /docker-entrypoint.sh: Configuration complete; ready for start up

$ curl localhost
curl: (7) Failed to connect to localhost port 80 after 0 ms: Connection refused

Same thing happens if the command is sudo docker-compose up --force-recreate -d nginx.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment