Let’s take look at what the subql docker-compose.yml means. Take for example the yaml file from the starter tutorial.
version: '3'
services:
postgres:
image: postgres:12-alpine
ports:
- 5432:5432
volumes:
- .data/postgres:/var/lib/postgresql/data
environment:
POSTGRES_PASSWORD: postgres
subquery-node:
image: onfinality/subql-node:latest
depends_on:
- "postgres"
restart: always
environment:
DB_USER: postgres
DB_PASS: postgres
DB_DATABASE: postgres
DB_HOST: postgres
DB_PORT: 5432
volumes:
- ./:/app
command:
- -f=/app
- --local
graphql-engine:
image: onfinality/subql-query:latest
ports:
- 3000:3000
depends_on:
- "postgres"
restart: always
environment:
DB_USER: postgres
DB_PASS: postgres
DB_DATABASE: postgres
DB_HOST: postgres
DB_PORT: 5432
command:
- --name=app
- --playground
Service
The service tag lists all the containers which are included in the compose file and acts as there parent task. (A service definition contains configuration that is applied to each container started for that service). Here there are services defined. postgress, subquery-node and graphql-engine.
Image
The base image of a container can be defined by either using a pre-existing image on DockerHub or by building an image using a Dockerfile. Here a predefined image from DockerHub is used with the image tag. Specifically postgres:12-alpine, onfinality/subql-node:latest and onfinality/subql-query:latest.
Port
We then define which port we want to expose and the host port it should be exposed to. eg 5432:5432 for host:container. The ports here are a straight same for same mapping. (A non same mapping would be something like 8080:80).
Volumes
Volumes are Docker’s preferred way of persisting data which is generated and used by Docker containers. They are completely managed by Docker and can be used to share data between containers and the Host system.
There are three types of volumes that can be defined. Normal, path and named. Here we use path mapping such as .data/postgres:/var/lib/postgresql/data. This defines the path on the host system and mapping it to a container destination using the semi-colon (:) operator.
Restart
The restart policy here is set as always. This means to always restart the container if it stops. If it is manually stopped, it is restarted only when Docker daemon restarts or the container itself is manually restarted.
Environment
Environment variables are used to bring configuration data into your applications. This is often the case if you have some configurations that are dependent on the host operating system or some other variable things that can change.
Here we define the default credentials and database parameters. It should be a given that this is not production quality code.