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:
version
refers to the docker-compose version (Latest 3)services
defines the services that we need to runapp
is a custom name for one of your containersimage
the image which we have to pull. Here we are usingnode:latest
andmongo
.container_name
is the name for each containerrestart
starts/restarts a service containerport
defines the custom port to run the containerworking_dir
is the current working directory for the service containerenvironment
defines the environment variables, such as DB credentials, and so on.command
is the command to run the service.
Last updated