Docker-compose File
The compose file is a YML file defining services, networks, and volumes for a Docker container. There are several versions of the compose file format available – 1, 2, 2.x, and 3.x.
version: '3'
services:
app:
image: node:latest
container_name: app_main
restart: always
command: sh -c "yarn install && yarn start"
ports:
- 8000:8000
working_dir: /app
volumes:
- ./:/app
environment:
MYSQL_HOST: localhost
MYSQL_USER: root
MYSQL_PASSWORD:
MYSQL_DB: test
mongo:
image: mongo
container_name: app_mongo
restart: always
ports:
- 27017:27017
volumes:
- ~/mongo:/data/db
volumes:
mongodb:versionrefers to the docker-compose version (Latest 3)servicesdefines the services that we need to runappis a custom name for one of your containersimagethe image which we have to pull. Here we are usingnode:latestandmongo.container_nameis the name for each containerrestartstarts/restarts a service containerportdefines the custom port to run the containerworking_diris the current working directory for the service containerenvironmentdefines the environment variables, such as DB credentials, and so on.commandis the command to run the service.
Last updated