Y
Y
YuriyCherniy2021-05-21 13:33:24
Nginx
YuriyCherniy, 2021-05-21 13:33:24

How to forward a port from a Docker container with a Django application to Nginx installed on localhost?

I use docker compose for deployment. Part of the yml file looks like this:

web:
    build: .
    volumes:
      - ./app_data:/app/media/favicon
      - ./static:/app/static
    ports:
      - 8000:8000
    restart: unless-stopped
    depends_on:
      - db

With this approach, the application can be accessed both on port 80, through Nginx, and on port 8000, bypassing Nginx, since the port is forwarded to local hosts. If we apply this approach:
expose:
  - 8000

Nginx does not see port 8000 because it is outside the container's internal network. How to correctly forward the port from the container so that Nginx can work with it and the user cannot access it.

Answer the question

In order to leave comments, you need to log in

1 answer(s)
C
chupasaurus, 2021-05-21
@YuriyCherniy

Normal approach: prescribe forwarding specifically on the loopback interface: ports:[127.3.2.1:8000:8000]
Based on thick hints, you want only nginx to have access to the port, for this you need to authorize it - through a firewall with an application definition or a proxy with authorization within the container network.
exposein the container information indicates that such and such ports are used, no action is taken.

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question