Last active
October 18, 2022 14:32
-
-
Save gabrielh-silvestre/624a3c6b9de184c1b12572996e3a68a7 to your computer and use it in GitHub Desktop.
copy/past docker-compose for express + mysql with ENV variables
This file contains hidden or 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
FRONT_PORT=3000 | |
PORT=3001 | |
DB_USER=user | |
DB_PASS=password | |
DB_NAME=database | |
DB_PORT=3306 | |
MONGO_PORT=27017 | |
REDIS_PORT=6379 |
This file contains hidden or 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: | |
zookeeper: | |
image: confluentinc/cp-zookeeper:latest | |
environment: | |
ZOOKEEPER_CLIENT_PORT: 2181 | |
extra_hosts: | |
- "host.docker.internal:172.17.0.1" | |
kafka: | |
image: confluentinc/cp-kafka:latest | |
depends_on: | |
- zookeeper | |
ports: | |
- "9092:9092" | |
- "9094:9094" | |
environment: | |
KAFKA_BROKER_ID: 1 | |
KAFKA_OFFSETS_TOPIC_REPLICATION_FACTOR: 1 | |
KAFKA_ZOOKEEPER_CONNECT: zookeeper:2181 | |
KAFKA_INTER_BROKER_LISTENER_NAME: INTERNAL | |
KAFKA_LISTENERS: INTERNAL://:9092,OUTSIDE://:9094 | |
KAFKA_ADVERTISED_LISTENERS: INTERNAL://kafka:9092,OUTSIDE://host.docker.internal:9094 | |
KAFKA_LISTENER_SECURITY_PROTOCOL_MAP: INTERNAL:PLAINTEXT,OUTSIDE:PLAINTEXT | |
extra_hosts: | |
- "host.docker.internal:172.17.0.1" | |
kafka-topics-generator: | |
image: confluentinc/cp-kafka:latest | |
depends_on: | |
- kafka | |
command: > | |
bash -c | |
"sleep 5s && | |
kafka-topics --create --topic=route.new-direction --if-not-exists --bootstrap-server=kafka:9092 && | |
kafka-topics --create --topic=route.new-position --if-not-exists --bootstrap-server=kafka:9092" |
This file contains hidden or 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.9' | |
services: | |
frontend: | |
image: node:16-alpine | |
command: npm run dev # ou npm start | |
restart: on-failure | |
working_dir: /app/frontend | |
volumes: | |
- ./front-end:/app/frontend | |
ports: | |
- ${FRONT_PORT}:3000 | |
environment: | |
- BACK_PORT=${BACK_PORT} | |
- BACK_HOST=backend | |
depends_on: | |
backend: | |
condition: service_healthy | |
healthcheck: | |
test: ['CMD', 'lsof', '-t', '-i:3000'] # Caso utilize outra porta interna para o front, altere ela aqui também | |
timeout: 10s | |
retries: 10 | |
backend: | |
image: node:16-alpine | |
command: npm run dev | |
restart: on-failure | |
working_dir: /app/backend | |
volumes: | |
- ./back-end:/app/backend | |
ports: | |
- 3001:${PORT} | |
tty: true | |
depends_on: | |
db: # mysql ou postgres | |
condition: service_healthy | |
environment: | |
- PORT=${PORT} | |
- DB_USER=${DB_USER} | |
- DB_PASS=${DB_PASS} | |
- DB_HOST=db # mysql ou postgres | |
- DB_NAME=${DB_NAME} | |
- DB_PORT=${DB_PORT} | |
healthcheck: | |
test: ["CMD", "lsof", "-t", "-i:3001"] # Caso utilize outra porta interna para o back, altere ela aqui também | |
timeout: 10s | |
retries: 5 | |
postgres: | |
image: postgres:14.3-alpine | |
restart: always | |
ports: | |
- ${DB_PORT}:5432 | |
environment: | |
- POSTGRES_USER=${DB_USER} | |
- POSTGRES_PASSWORD=${DB_PASS} | |
- POSTGRES_DB=${DB_NAME} | |
healthcheck: | |
test: ["CMD-SHELL", "pg_isready", "-d", "db_prod"] | |
interval: 30s | |
timeout: 60s | |
retries: 10 | |
start_period: 30s | |
cap_add: | |
- SYS_NICE # Deve omitir alertas menores | |
mysql: | |
image: mysql:8.0.21 | |
container_name: db | |
ports: | |
- ${DB_PORT}:3306 | |
environment: | |
- MYSQL_USER=${DB_USER} | |
- MYSQL_PASSWORD=${DB_PASS} | |
- MYSQL_ROOT_PASSWORD=${DB_PASS} | |
# - MYSQL_RANDOM_ROOT_PASSWORD=true | |
- MYSQL_DATABASE=${DB_NAME} | |
restart: 'always' | |
healthcheck: | |
test: ["CMD", "mysqladmin" ,"ping", "-h", "localhost"] | |
interval: 30s | |
timeout: 10s | |
retries: 10 | |
start_period: 30s | |
cap_add: | |
- SYS_NICE # Deve omitir alertas menores | |
mongo: | |
image: mongo:5.0.7 | |
restart: always | |
ports: | |
- ${MONGO_PORT}:27017 | |
healthcheck: | |
test: echo 'db.runCommand("ping").ok' | mongo mongo:27017/test --quiet | |
interval: 10s | |
timeout: 10s | |
retries: 5 | |
start_period: 40s | |
environment: | |
- MONGO_INITDB_ROOT_USERNAME=${DB_USER} | |
- MONGO_INITDB_ROOT_PASSWORD=${DB_PASSWORD} | |
cap_add: | |
- SYS_NICE # Deve omitir alertas menores | |
redis: | |
image: redis:7-alpine | |
ports: | |
- ${REDIS_PORT}:6379 | |
restart: 'always' | |
healthcheck: | |
test: ['CMD', 'redis-cli', 'ping'] | |
interval: 30s | |
timeout: 10s | |
retries: 10 | |
start_period: 30s | |
cap_add: | |
- SYS_NICE # Deve omitir alertas menores |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment