-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathdocker-compose.yml
More file actions
92 lines (89 loc) · 3.38 KB
/
docker-compose.yml
File metadata and controls
92 lines (89 loc) · 3.38 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
#
# Notes for this revision of the docker-compose.yml file:
# - The MySQL service is commented out, as the MySQL database is running on a separate host.
# - The DB_HOST environment variable is set to the IP address of the host where the MySQL database is running.
# - The DB_USER and DB_PASSWORD environment variables are set to the values of the corresponding
# environment variables in the host environment. Here is an example docker-compose up command:
# DB_USER=yourusername DB_PASSWORD=yourpassword docker-compose up
# - the user 'DB_USER'@'DB_HOST' must have the necessary permissions to access the 'employees' database that
# is being accessed by the node application (the mysql service running on local machine).
# - Here are the necessary privilege commands required to be run on the MySQL database:
# i.) GRANT ALL PRIVILEGES ON *.* TO 'DB_USER'@'DB_HOST'
# ii.) FLUSH PRIVILEGES
# iii.) If the user doesn't already exist, then run the following command before the GRANT:
# CREATE USER 'DB_USER'@'DB_HOST' IDENTIFIED BY 'DB_PASSWORD'
#
# Miscellaneous notes:
# - command to find the IP address or hostname of the host machine (MacOS):
# - ipconfig getifaddr en0
# - scutil --get LocalHostName
# - hostname
# - miscellaneous docker-compose commands:
# - docker-compose build
# - docker-compose up
# - docker-compose down
# - docker-compose ps
# - docker-compose logs
# - docker-compose exec app sh
# - docker-compose exec sh
# - docker-compose exec app ls
# - docker-compose exec app curl -I
#
# - docker-compose exec app ping -c 4 10.0.0.50
# - docker-compose exec app mysql -h 192.168.1.100 -u root -p
# - docker-compose exec app sh -c 'apt-get update && apt-get install -y mysql-client'
# - docker-compose exec app mysql -h yourhostname -u yourusername -p
#
version: '3.8'
services:
db:
image: mysql:8.4.0
ports:
- "3307:3306" # Map the container's port 3306 to port 3307 on your host
environment:
MYSQL_ROOT_PASSWORD: ${DB_PASSWORD}
MYSQL_DATABASE: ${DB_NAME}
volumes:
- ./init/mysql/sql_scripts:/docker-entrypoint-initdb.d
healthcheck:
test: ["CMD", "mysql", "-u", "root", "-p${MYSQL_ROOT_PASSWORD}", "-e", "SELECT 1"]
interval: 15s
timeout: 180s
retries: 10
app:
image: employee-node-ts
build:
context: .
dockerfile: Dockerfile
ports:
- "8080:3000"
environment:
- NODE_ENV=production
# - DB_HOST=db
# - DB_HOST=10.0.0.50
# - DB_NAME=employees
- DB_HOST=${DB_HOST}
- DB_USER=${DB_USER}
- DB_PASSWORD=${DB_PASSWORD}
- DB_NAME=${DB_NAME}
- DB_PORT=${DB_PORT}
- AWS_REGION=${AWS_REGION},
- AWS_ACCESS_KEY_ID=${AWS_ACCESS_KEY_ID},
- AWS_SECRET_ACCESS_KEY=${AWS_SECRET_ACCESS_KEY},
depends_on:
db:
condition: service_healthy
# The section pulls a MySQL image from Docker Hub.
# docker-compose up would start both this node service and the MySQL service container; and
# would require loading the employees DDL/data into the MySQL container (or restoring
# a backup of the employees database).
#
# For initial local testing, this is commented out and the DB_HOST variable pointed
# at the host where the MySQL database is running.
# db:
# image: mysql:8.4.0
# environment:
# MYSQL_ROOT_PASSWORD:
# MYSQL_DATABASE: employees
# ports:
# - "3306:3306"