I am attempting to containerize my python backend that I am hosting on a GCP compute engine instance. I created two containers, one for the backend server and one for nginx reverse proxy. My docker-compose.yml:
services:
web:
image: <me>/fastapiwithnginx:latest
container_name: web
ports:
- "8001:8001"
restart: unless-stopped
logging:
driver: "json-file"
options:
max-file: "1"
max-size: "100k"
nginx:
restart: unless-stopped
image: nginx
container_name: nginx
ports:
- "443:443"
environment:
- CERTBOT_EMAIL=<my-email>
volumes:
- ./nginx:/etc/nginx/user_conf.d:ro
# - /etc/letsencrypt/:/etc/letsencrypt
depends_on:
- web
logging:
driver: "json-file"
options:
max-size: "100k"
max-file: "1"
I am able to pull both images in my VM and start containers. I am able to connect to the backend by hitting the ip address at port 8001, but I am unable to connect using my server url. I get a net::ERR_CONNECTION_REFUSED.
My nginx.conf is below:
server {
listen 443 ssl ;
listen [::]:443 ssl ;
root /var/www/html;
# Add index.php to the list if you are using PHP
index index.html index.htm index.nginx-debian.html;
server_name <my-server-url>; # managed by Certbot
location / {
proxy_pass http://web:8001;
}
ssl_certificate /etc/letsencrypt/live/isgs-server.uow-carbon.org/fullchain.pem;
ssl_certificate_key /etc/letsencrypt/live/isgs-server.uow-carbon.org/privkey.pem;
}
When I run docker ps -a
on my vm, I see the following:
ca318e7b0788 nginx "/docker-entrypoint.…" 20 minutes ago Up 16 seconds 80/tcp, 0.0.0.0:443->443/tcp, :::443->443/tcp nginx
7cf921b40eab <me>/fastapiwithnginx:latest "python app/main.py …" 20 minutes ago Up 20 minutes 0.0.0.0:8001->8001/tcp, :::8001->8001/tcp web
Any ideas where I’m going wrong?