Answer the question
In order to leave comments, you need to log in
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.loc
it 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;
}
}
docker run -p 80:80 -v /Users/vasya/nginx/conf.d:/etc/nginx/conf.d:ro -d nginx
502 Bad Gateway
(i.e. nginx in the docker sees the config normally, but it can’t get through to 127.0.0.1:3000
which is spinning on the host (it’s understandable). This is where my docker knowledge ended ... Answer the question
In order to leave comments, you need to log in
You forgot to turn off network isolation, add --net=host
and 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=host
it is not needed in this case, but it is worth checking.
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question