Is there a way to specify an empty array in docker-compose.yml?
I tried ports: [] to no avail.
A JSON empty array literal should be valid YAML syntax, but when I use this, I get the following error from Docker:
services.myapp_migrations.ports must be a list
For more context:
I have a python application with the following docker-compose.yml:
version: "3.9"
services:
myapp: &myapp
build:
context: .
ports:
- 8000:8000
environment:
- MYAPP_DB_HOST=postgres
volumes:
- ./.env:/app/.env
working_dir: /app
depends_on:
- postgres
myapp_migrations:
<<: *myapp
command: ["migrate"]
restart: on-failure
ports: []
postgres:
image: postgres:12-alpine
environment:
- POSTGRES_PASSWORD=${MYAPP_DB_PASSWORD}
- POSTGRES_USER=${MYAPP_DB_USER}
- POSTGRES_DB=${MYAPP_DB_NAME}
As you can see, I'm trying to re-use the myapp definition with a YAML anchor, but I need to override the ports definition in myapp_migrations.
(I know I could use extension fields for this, but I'm trying to avoid that.)