J
J
jeruthadam2020-04-25 22:06:13
Nginx
jeruthadam, 2020-04-25 22:06:13

How to set up docker + nginx for local development?

The final task - I want to run the front of the application locally (the application is not in the docker), let it be on port 3000, and open it at test.loc in the browser. At the same time, nginx should run in the docker, but read the configs from the local directory so that you can conveniently change the configs.

What I did: raised the application to 3000, added 127.0.0.1 test.locit to the hosts, made a local directory for nginx configs, added the config:

server {
  listen 80;
  server_name test.loc;

  location / {
    proxy_pass http://127.0.0.1:3000;
  }
}


run docker with command
docker run -p 80:80 -v /Users/vasya/nginx/conf.d:/etc/nginx/conf.d:ro -d nginx


Unfortunately, it didn’t work, it writes in the browser 502 Bad Gateway(i.e. nginx in the docker sees the config normally, but it can’t get through to 127.0.0.1:3000which is spinning on the host (it’s understandable). This is where my docker knowledge ended ...

How to configure to my Wishlist?

Answer the question

In order to leave comments, you need to log in

1 answer(s)
C
chupasaurus, 2020-04-25
@jeruthadam

You forgot to turn off network isolation, add --net=hostand remove --port(it will be pointless). Naturally, the 80th port on the host must be free, otherwise edit the nginx config for the container.
Addendum: if you have Windows, then loopback will not be available, only applications listening on all interfaces, for this, an address has been set in the docker dns host.docker.internal( documentation ). On the Mac, loopback is available at docker.for.mac.localhost, on Windows, I dug up contradictory things. As I understand --net=hostit is not needed in this case, but it is worth checking.

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question