Newby question regarding docker-compose: services.app.volumes must be a list

I’m rather new to Docker and following along with the Docker getting started tutorial that comes after you first install Docker Desktop for Windows. It all went swimmingly until it came to docker-compose section where I get an error I can’t get past. Here is the docker compose I created based on the instructions:

version: "3.8"

services:
  app:
    image: node:12-alpine
    command: sh -c "yarn install && yarn run dev"
    ports:
      -3000:3000
    working_dir: /app
    volumes:
      -./:app
    environment:
      MYSQL_HOST: mysql
      MYSQL_USER: root
      MYSQL_PASSWORD: secret
      MYSQL_DB: todos
  mysql:
    image: mysql:5.7
    volumes:
      - todo-mysql-data:/var/lib/mysql
    environment: 
      MYSQL_ROOT_PASSWORD: secret
      MYSQL_DATABASE: todos

volumes:
  todo-mysql-data:

And here is the results:

C:\temp\app>docker compose up -d
services.app.volumes must be a list

C:\temp\app>

Where did I screw up?

For volumes and ports, each list item starts with a hyphen, followed by space and then its value.
Though, your list items for the app service miss the space between the hyphen and the value.

Thank you. I tried to add a space but that did not make a difference. Here is how it is now:

    volumes:
      - ./:app

I haven’t notice before, but the taget can’t be right like that. Its either /host/path:/container/path or volume-name:/container/path. Are your sure the error message is still the same? It shouldnt have been.

update haven’t notice that its DDfW: I am not sure if ./ is a valid path from Powershells perspective either. Though I assume you ment - .:/app instead of - ./:app. I have no idea how to get the current path in a compose file on windows.

yep, just tried it again. here is the output along with content of the yml file

C:\temp\app>type docker-compose.yml
version: "3.8"

services:
  app:
    image: node:12-alpine
    command: sh -c "yarn install && yarn run dev"
    ports:
      -3000:3000
    working_dir: /app
    volumes:
      - ./:app
    environment:
      MYSQL_HOST: mysql
      MYSQL_USER: root
      MYSQL_PASSWORD: secret
      MYSQL_DB: todos
  mysql:
    image: mysql:5.7
    volumes:
      - todo-mysql-data:/var/lib/mysql
    environment:
      MYSQL_ROOT_PASSWORD: secret
      MYSQL_DATABASE: todos

volumes:
  todo-mysql-data:
C:\temp\app>docker compose up -d
services.app.ports must be a list

C:\temp\app>

For this, @meyay explained you needed to add the space in your -./:app. Now, after fixing that, the error changed into:

So, the same solution applies to your -3000:3000.

1 Like

Ahhh Thanks you. I swear I know how to read, I just fail to read sometimes :smiley: :stuck_out_tongue:
OK making progress. Now it is having problem with the path I provided. Must the path be hard coded to a specific absolute path? That seems to have some portability issues, which seems to counter to the idea of docker being highly portable.

C:\temp\app>docker compose up -d
[+] Running 3/4
 - Network app_default           Created                                                                                                                             0.1s
 - Volume "app_todo-mysql-data"  Created                                                                                                                             0.0s
 - Container app-app-1           Creating                                                                                                                            0.2s
 - Container app-mysql-1         Created                                                                                                                             0.2s
Error response from daemon: invalid volume specification: '/run/desktop/mnt/host/c/temp/app:app:rw': invalid mount config for type "bind": invalid mount path: 'app' mount path must be absolute

C:\temp\app>

OK it was having an issue with the container path, not the host path. This worked now

version: "3.8"

services:
  app:
    image: node:12-alpine
    command: sh -c "yarn install && yarn run dev"
    ports:
      - 3000:3000
    working_dir: /app
    volumes:
      - ./:/app
    environment:
      MYSQL_HOST: mysql
      MYSQL_USER: root
      MYSQL_PASSWORD: secret
      MYSQL_DB: todos
  mysql:
    image: mysql:5.7
    volumes:
      - todo-mysql-data:/var/lib/mysql
    environment: 
      MYSQL_ROOT_PASSWORD: secret
      MYSQL_DATABASE: todos

volumes:
  todo-mysql-data:

Thanks again for all your help, really appreciate it

1 Like

Yes. You may want to read the following again, to understand:

Docker needs the slashes to know what it is looking at.

2 Likes