eg3 finished Backend + Frontend cross communication
parent
43a2dfefc7
commit
7bdffc22cf
|
@ -14,4 +14,22 @@ How to test it:
|
|||
How to test it:
|
||||
1. Comment all other containers
|
||||
2. Run `docker compose build` & `docker compose up`
|
||||
3. Test by `curl localhost`, should return a html file (as `/eg3/frontend/index.html`)
|
||||
3. 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:
|
||||
1. Comment out proxy container
|
||||
2. frontend has port 80 exposed; backend has port 5000 exposed;
|
||||
3. Run `docker compose build` & `docker compose up`
|
||||
4. Create a network: `docker network create mynetwork`
|
||||
5. Add containers into network
|
||||
1. `docker network connect mynetwork backend`
|
||||
2. `docker network connect mynetwork frontend`
|
||||
6. Inspect `mynetwork` has containers `docker network inspect mynetwork`
|
||||
7. Test network:
|
||||
1. Enter frontend container: `docker exec -it frontend /bin/sh`
|
||||
2. Make a request to backend: `curl http://backend:5000`
|
||||
3. Get response `{"version": "1.0.0"}`
|
|
@ -20,10 +20,10 @@ services:
|
|||
ports:
|
||||
- "80:80" # Uncomment this line if you want to run the frontend container only
|
||||
|
||||
# backend:
|
||||
# container_name: backend
|
||||
# build:
|
||||
# context: ./backend
|
||||
# dockerfile: Dockerfile
|
||||
# ports:
|
||||
# - "5000:5000" # Uncomment this line if you want to run the backend container only
|
||||
backend:
|
||||
container_name: backend
|
||||
build:
|
||||
context: ./backend
|
||||
dockerfile: Dockerfile
|
||||
ports:
|
||||
- "5000:5000" # Uncomment this line if you want to run the backend container only
|
Loading…
Reference in New Issue