Jason Zhu 7074e55f40 | ||
---|---|---|
.. | ||
backend | ||
frontend | ||
proxy | ||
README.md | ||
docker-compose.yaml |
README.md
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
- Remove exposed of both containers, as we they don't need expose their ports to outside environment. We just want to test their cross-communication in the same docker network
- port 80 for frontend;
- port 5000 for backend;
- 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: