Compare commits
2 Commits
7bdffc22cf
...
038455b315
Author | SHA1 | Date |
---|---|---|
Jason Zhu | 038455b315 | |
Jason Zhu | 7074e55f40 |
|
@ -22,7 +22,9 @@ In this section, we test frontend container can cross-communicate with backend c
|
||||||
|
|
||||||
Steps:
|
Steps:
|
||||||
1. Comment out proxy container
|
1. Comment out proxy container
|
||||||
2. frontend has port 80 exposed; backend has port 5000 exposed;
|
2. 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
|
||||||
|
1. port 80 for frontend;
|
||||||
|
2. port 5000 for backend;
|
||||||
3. Run `docker compose build` & `docker compose up`
|
3. Run `docker compose build` & `docker compose up`
|
||||||
4. Create a network: `docker network create mynetwork`
|
4. Create a network: `docker network create mynetwork`
|
||||||
5. Add containers into network
|
5. Add containers into network
|
||||||
|
@ -33,3 +35,23 @@ Steps:
|
||||||
1. Enter frontend container: `docker exec -it frontend /bin/sh`
|
1. Enter frontend container: `docker exec -it frontend /bin/sh`
|
||||||
2. Make a request to backend: `curl http://backend:5000`
|
2. Make a request to backend: `curl http://backend:5000`
|
||||||
3. Get response `{"version": "1.0.0"}`
|
3. Get response `{"version": "1.0.0"}`
|
||||||
|
|
||||||
|
# Proxy using nginx
|
||||||
|
|
||||||
|
In this section, we test we can reach both frontend and backend from proxy container or computer itself
|
||||||
|
|
||||||
|
Steps:
|
||||||
|
1. Uncomment all container in `docker-compose.yaml`
|
||||||
|
2. Build container and initiate them via `docker compose up`
|
||||||
|
3. These container are not in `mynetwork`
|
||||||
|
4. Enter proxy container via `docker exec -it proxy /bin/sh`
|
||||||
|
5. From the proxy container, try to reach other containers
|
||||||
|
1. Frontend
|
||||||
|
1. `curl http://frontend`
|
||||||
|
2. `curl http://localhost` to visit port 80
|
||||||
|
2. Backend
|
||||||
|
1. `curl http://backend:5000`
|
||||||
|
2. `curl http://localhost/api`
|
||||||
|
6. Exit the container; In normal terminal, we can still reach frontend and backend
|
||||||
|
1. `curl http://localhost` to visit frontend
|
||||||
|
2. `curl http://localhost/api` to visit backend
|
|
@ -1,29 +1,25 @@
|
||||||
version: '3.8'
|
version: '3.8'
|
||||||
|
|
||||||
services:
|
services:
|
||||||
# proxy:
|
proxy:
|
||||||
# container_name: proxy
|
container_name: proxy
|
||||||
# build:
|
build:
|
||||||
# context: ./proxy
|
context: ./proxy
|
||||||
# dockerfile: Dockerfile
|
dockerfile: Dockerfile
|
||||||
# ports:
|
ports:
|
||||||
# - "80:80"
|
- "80:80"
|
||||||
# depends_on:
|
depends_on:
|
||||||
# - frontend
|
- frontend
|
||||||
# - backend
|
- backend
|
||||||
|
|
||||||
frontend:
|
frontend:
|
||||||
container_name: frontend
|
container_name: frontend
|
||||||
build:
|
build:
|
||||||
context: ./frontend
|
context: ./frontend
|
||||||
dockerfile: Dockerfile
|
dockerfile: Dockerfile
|
||||||
ports:
|
|
||||||
- "80:80" # Uncomment this line if you want to run the frontend container only
|
|
||||||
|
|
||||||
backend:
|
backend:
|
||||||
container_name: backend
|
container_name: backend
|
||||||
build:
|
build:
|
||||||
context: ./backend
|
context: ./backend
|
||||||
dockerfile: Dockerfile
|
dockerfile: Dockerfile
|
||||||
ports:
|
|
||||||
- "5000:5000" # Uncomment this line if you want to run the backend container only
|
|
Loading…
Reference in New Issue