1.3 KiB
1.3 KiB
e.g. 3: Create an Ningx Reverse Proxy With Docker
How To Run Multiple Docker Containers Under One URL
Backend only
How to test it:
- Comment all other containers
- Run
docker compose build
&docker compose up
- Test by
curl localhost:5000
, should return{"version":"1.0.0"}
Frontend only
How to test it:
- Comment all other containers
- Run
docker compose build
&docker compose up
- Test by
curl localhost
, should return a html file (as/eg3/frontend/index.html
)
Backend + Frontend
In this section, we test frontend container can cross-communicate with backend container.
Steps:
- Comment out proxy container
- frontend has port 80 exposed; backend has port 5000 exposed;
- Run
docker compose build
&docker compose up
- Create a network:
docker network create mynetwork
- Add containers into network
docker network connect mynetwork backend
docker network connect mynetwork frontend
- Inspect
mynetwork
has containersdocker network inspect mynetwork
- Test network:
- Enter frontend container:
docker exec -it frontend /bin/sh
- Make a request to backend:
curl http://backend:5000
- Get response
{"version": "1.0.0"}
- Enter frontend container: