1

I have docker-compose.yml like following

version: '3'

services:
  api-server:
    build: ./api
    links:
      - 'db'
    ports:
      - '3000:3000'
    volumes:
      - ./api:/src
      - ./src/node_modules
    tty: true
    container_name: api-server

  db:
    build:
      context: .
      dockerfile: ./db/Dockerfile
    restart: always
    hostname: db
    environment:
      MYSQL_ROOT_PASSWORD: test
      MYSQL_USER: test
      MYSQL_PASSWORD: test
      MYSQL_DATABASE: test
    volumes:
      - './db:/config'
    ports:
      - 3306:3306
    container_name: db

When I tried to docker-compose up

$ docker-compose up -d

I suffered some error like following one.

It seems like to set them absolute path. but before this message didn't appeared.

I'd like to know

①What cause this error.

③How to fix it without rewrite to absolute path.

db is up-to-date
Recreating bf6187ceff2f_api-server ... error
ERROR: for bf6187ceff2f_api-server  Cannot create container for service api-server: invalid volume specification: '9131f8ce856163b2935bd8f09d5e6a2e67509fd5adee9b2d1903cd760639beaa:src/node_modules:rw': invalid mount config for type "volume": invalid mount path: 'src/node_modules' mount path must be absolute
ERROR: for api-server  Cannot create container for service api-server: invalid volume specification: '9131f8ce856163b2935bd8f09d5e6a2e67509fd5adee9b2d1903cd760639beaa:src/node_modules:rw': invalid mount config for type "volume": invalid mount path: 'src/node_modules' mount path must be absolute

ERROR: Encountered errors while bringing up the project.

If someone has opinion,please let me know.

Thanks

Heisenberg
  • 4,787
  • 9
  • 47
  • 76

1 Answers1

1

Just saw that you're trying to do this.

The error you're describing is happening because you need to specify the absolute path inside the container, so it mounts over a volume. Something like this: /src/node_modules

Gustavo Kawamoto
  • 2,665
  • 18
  • 27
  • This is the answer. Remove the . before the ./src/node_modules as you need the absolute path inside the container. The ./ makes it a relative path. – OctaviaLo Dec 29 '22 at 03:17