Last active
April 28, 2022 05:35
-
-
Save hucancode/6a28cf72d6519bf8613e1c72c0b4672c to your computer and use it in GitHub Desktop.
Setup NodeJS/MySQL with Docker
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
version: "3" | |
services: | |
app: | |
image: app | |
build: . | |
environment: | |
HOST: localhost | |
DATABASE_HOST: db | |
DATABASE_PORT: 3306 | |
DATABASE_NAME: app-db | |
DATABASE_USERNAME: app-user | |
DATABASE_PASSWORD: secret | |
ports: | |
- 3000:3000 | |
command: npm run dev | |
volumes: | |
# mount current dir into docker container, should be removed in production | |
- .:/app | |
# ignore local node_modules, use container, should be removed in production | |
- /app/node_modules | |
depends_on: | |
db: | |
condition: service_healthy | |
restart: always | |
db: | |
image: mysql/mysql-server | |
environment: | |
MYSQL_ROOT_PASSWORD: secret | |
MYSQL_DATABASE: app-db | |
MYSQL_USER: app-user | |
MYSQL_PASSWORD: secret | |
command: ["mysqld", | |
"--default-authentication-plugin=mysql_native_password", | |
"--general-log=1", | |
"--general-log-file=/var/lib/mysql/general-log.log"] | |
# make sure /var/lib/mysql/mysql.sock exists on your local machine | |
volumes: | |
- ../admin-data:/var/lib/mysql:rw | |
healthcheck: | |
test: ["CMD", "mysqladmin" ,"ping", "-h", "localhost"] | |
timeout: 20s | |
retries: 10 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# Use the official lightweight Node.js 16 image. | |
# https://hub.docker.com/_/node | |
FROM node:16-slim | |
WORKDIR /app | |
COPY . ./ | |
RUN npm ci && npm run build |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment