Home > Blockchain >  docker-compose volumes: no such file or directory
docker-compose volumes: no such file or directory

Time:12-22

I have the following folder structure:

scripts/
--constraints.cypher
docker-compose.yml

This is my docker-compose.yml:

services:
  app-config-db:
    image: neo4j:latest
    container_name: app-config-db
    ports:
      - "7474:7474"
      - "7473:7473"
      - "7687:7687"
    volumes:
      - ./scripts:/var/lib/neo4j/scripts
    environment:
      - NEO4J_AUTH=neo4j/test123!
    command:
      - cypher-shell -u neo4j -p test123! --file /var/lib/neo4j/scripts/constraints.cypher

But when I run docker-compose up I get the following error:

error: exec: "cypher-shell -u neo4j -p test123! --file /var/lib/neo4j/scripts/constraints.cypher": stat cypher-shell -u neo4j -p test123! --file /var/lib/neo4j/scripts/constraints.cypher: no such file or directory

To me, it seems like the .scripts directory is not mounting correctly into my docker container, but everything seems in order. What am I doing wrong?

CodePudding user response:

The scripts directory gets mounted correctly. The problem here is that you are specifying the command in an array form so docker searches for the executable file "cypher-shell -u neo4j -p test123! --file /var/lib/neo4j/scripts/constraints.cypher" which is obviously not found. You can either specify the command as a string

services:
  app-config-db:
    image: neo4j:latest
    container_name: app-config-db
    ports:
      - "7474:7474"
      - "7473:7473"
      - "7687:7687"
    volumes:
      - ./scripts:/var/lib/neo4j/scripts
    environment:
      - NEO4J_AUTH=neo4j/test123!
    command: cypher-shell -u neo4j -p test123! --file /var/lib/neo4j/scripts/constraints.cypher

Or split all the options up:

services:
  app-config-db:
    image: neo4j:latest
    container_name: app-config-db
    ports:
      - "7474:7474"
      - "7473:7473"
      - "7687:7687"
    volumes:
      - ./scripts:/var/lib/neo4j/scripts
    environment:
      - NEO4J_AUTH=neo4j/test123!
    command:
      - cypher-shell
      - -u
      - neo4j
      - -p
      - test123!
      - --file
      - /var/lib/neo4j/scripts/constraints.cypher

This is similar to the CMD instruction in the Dockerfile. You can find more info in the compose file spec and the documentation for CMD.

  • Related