In this step, we will learn how to use docker-compose.
📖 Reference
Revisit STEP4 and build a docker image for running the web frontend
You have a sample Dockerfile
In typescript/simple-mercari-web
. Modify this file to run frontend on Docker.
- Set the name of the repository as
build2024/web
and tag aslatest
.
Run the following and check if you can successfully open http://localhost:3000/ on your browser.
$ docker run -d -p 3000:3000 build2024/web:latest
Install Docker Compose and check you can run docker-compose -v
📖 Reference
Go through Docker Compose tutorial
📌 Sample code is in Python but the knowledge of Python or the environment is not necessary. Use this tutorial regardless of the backend language you chose in STEP3.
🔰 Point
Let's check if you can answer the following questions.
- How many services are defined in the docker-compose file in the tutorial? What exactly do these services do?
- web service and redis services get docker images with different methods. When running
docker-compose up
, check how where each image id downloaded. - In docker-compose, you can connect to different services from a service. How does the web service resolve the name for the redis service and connect to it?
Referring to the tutorial material, run the frontend and API using Docker Compose
Set up docker-compose.yml
under mercari-build-training/
Make a new file docker-compose.yml
considering the following points.
- Docker image to use
- (Option 1: Difficulty ☆) Use
build2024/app:latest
andbuild2024/web:latest
made in STEP4 and STEP6-1 - (Option 2: Difficulty ☆☆☆) Build from
{go|python}/Dockerfile
andtypescript/simple-mercari-web/Dockerfile
- (Option 1: Difficulty ☆) Use
- Port numbers
- API : 9000
- Frontend : 3000
- Connecting between services
- Frontend should send requests to an environment variable
REACT_APP_API_URL
- While API will not send requests to frontend, CORS needs to be set up such that frontend knows where the requests are coming from
- Set an environment variable
FRONT_URL
for frontend URL
- Frontend should send requests to an environment variable
Run docker-compose up
and check if the following operates properly
- http://localhost:3000/ displays the frontend page
- You can add an new item (Listing)
- You can view the list of all items (ItemList)