전체 파일 구조
- react-nodejs(메인 폴더)
- client (클라이언트 폴더)
- create-react-app
- package.json
- package-lock.json
- create-react-app
- node-modules
*server (서버 폴더)
- server.js
- package.json
- package-lock.json
- node-modules
- package.json
- yarn.lock
정말 정말 간단한 mysql과 연결한 react-node web app 입니다.
링크 : https://hub.docker.com/_/mysql
docker pull jung660317/react-node-app-with-mysql
docker exec -it <mysql container name> /bin/bash
mysql -u root -p
테이블의 필드의 이름은 아무거나 상관없지만 하나의 필드만 적용해야 합니다
create database db;
use db;
create table table1(name char(20));
version: '3.1'
services:
mysql:
image: mysql
command: --default-authentication-plugin=mysql_native_password
restart: always
container_name: mysql
network_mode: host
environment:
MYSQL_ROOT_PASSWORD: admin
adminer:
image: adminer
restart: always
network_mode: host
ports:
- 8080:8080
react-node-app-with-mysql:
image: jung660317/react-node-app-with-mysql
container_name: react-node-app
restart: always
ports:
- 3000:3000
network_mode: host
docker-compose up -d --build
정상 동작 확인
input 창에 입력한 데이터를 넣어줍니다.
mysql 데이터베이스에 들어간 데이터를 보여줍니다.
mysql 데이터베이스에 들어간 데이터를 모두 삭제합니다.