1

I want to run nginx inside a docker container as a reverse proxy to talk to an instance of gunicorn running on the host machine (possibly inside another container, but not necessarily). I've seen solutions involving docker compose but I'd like to learn how to do it "manually" first without learning a new tool, right now.

The simplified version of the problem is this:

  1. Say I run a docker container on my machine.
  2. Outside the container, I run gunicorn on port 5000.
  3. From within the container, I want to run ping ??? and have it reach the gunicorn instance run in step 2.

How can I do this in a simple, portable way?

Jack M
  • 4,769
  • 6
  • 43
  • 67
  • Possible duplicate of [From inside of a Docker container, how do I connect to the localhost of the machine?](https://stackoverflow.com/questions/24319662/from-inside-of-a-docker-container-how-do-i-connect-to-the-localhost-of-the-mach) – David Maze Apr 24 '19 at 10:18

1 Answers1

0

The easiest way is to run gunicorn in its own container and expose port 5000 (not map it, just expose it).

It is important to create a network first and run both your containers on the same network so that they see each other: docker network create xxxx

The when you run your 2 containers attach them to this network: docker run ... --network xxxx ...

Give names to your your containers, it is a good practice. (eg: docker run ... --name gunicorn ...)

Now from your container you can ping your gunicorn container: ping gunicorn, or even telnet on on port 5000.

If you need more information just drop me a comment.

Mihai
  • 9,526
  • 2
  • 18
  • 40