The provided compose.yaml composed of 2 services
- Express.js router
- MySQL server
Note: Using volume for database persistent storage.
- Express.js
- node:21.6.2
-
"dependencies": { "cors": "^2.8.5", "express": "^4.18.3", "mysql2": "^3.9.2" }
- MySQL
-
mysql/mysql-server:8.0.32
-
MYSQL_ROOT_PASSWORD= rootpw -
MYSQL_USER= user -
MYSQL_PASSWORD= userpw -
MYSQL_DATABASE= myapp -
init file under
mysql_init/-
~$ describe myapp.user; +-----------------------+----------+------+-----+---------+-------+ | Field | Type | Null | Key | Default | Extra | +-----------------------+----------+------+-----+---------+-------+ | user | char(32) | NO | PRI | | | | authentication_string | text | YES | | NULL | | +-----------------------+----------+------+-----+---------+-------+
-
-
docker compose up -dThis should create a network, a volume, and two containers. Make sure that said volume is empty or does not already exist if you are doing this the first time.
- Port
3000onlocalhostshould now be listened by the app. - MySQL service is mapped to port
3001.
Do the following if a clean reset is needed.
docker compose down && docker volume rm myapp_mysql_volAnd then go back to upping the compose.
Supporting routes of the current version:
/– GET/user/auth– POST/user/register– POST (still a dummy)
Under test/ is a sample test file requesting http://localhost:3000/user/auth route.
NOTE: Check the status code of response after fetching –
200means good to go.console.log(response.status);