> For the complete documentation index, see [llms.txt](https://devops-3.gitbook.io/devops/llms.txt). Markdown versions of documentation pages are available by appending `.md` to page URLs; this page is available as [Markdown](https://devops-3.gitbook.io/devops/docs/module-7-docker/docker-compose-file.md).

# 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.

```yaml
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 run
* `app` is a custom name for one of your containers
* `image` the image which we have to pull. Here we are using `node:latest` and `mongo`.
* `container_name` is the name for each container
* `restart` starts/restarts a service container
* `port` defines the custom port to run the container
* `working_dir` is the current working directory for the service container
* `environment` defines the environment variables, such as DB credentials, and so on.
* `command` is the command to run the service.
