This is an implementation of multi container in docker and to containerize DB ( MYSQL ) in one container and Node JS in another container.
docker compose up
version: "3.8"
services:
app:
build:
context: .
dockerfile: Dockerfile
ports:
- 3000:3000
volumes:
- .:/usr/src/app
- '/usr/src/app/node_modules'
depends_on:
- mysql_server
mysql_server:
command: --default-authentication-plugin=mysql_native_password
image: mysql:5.7
environment:
- MYSQL_DATABASE=TCE
- MYSQL_USER=thiru
- MYSQL_PASSWORD=1234
- MYSQL_ROOT_PASSWORD=1234
# Latest Node Version
FROM node:latest
WORKDIR /usr/src/app
COPY package*.json .
RUN npm install
VOLUME [ "/usr/src/app/node_modules" ]
COPY . .
EXPOSE 3000
CMD ["node", "index.js"]