0

When initially building containers using Docker-compose, I forgot to put a credentials.json file in the directory before running docker-compose up. Now Docker seems to always assume credentials.json is a directory and not a file even if I have the file in the directory (see error below).

ERROR: for pair-backend  Cannot start service pair-backend: 
OCI runtime create failed: container_linux.go:367: starting container process caused: process_linux.go:495: container init caused: rootfs_linux.go:60: 
mounting "/host_mnt/Users/leed36/Desktop/GitHub/pair-app/credentials.json" to rootfs at "/var/lib/docker/overlay2/6808dee4b6f47e47f39143231ee71bb1728292fb69e2a672388bc1ba42c42ebd/merged/app/credentials.json" 
caused: not a directory: unknown: Are you trying to mount a directory onto a file (or vice-versa)? Check if the specified host path exists and is the expected type

I have tried deleting the containers, docker system prune -a and docker volume prune and I still can't get Docker to mount this file.

Here is the docker-compose definition

    container_name: pair-backend
    build:
      context: ./backend
      dockerfile: Dockerfile
    env_file:
      - ./backend/.env
    volumes:
      - ./backend:/app/
      - ./credentials.json:/app/credentials.json

The only way I can get this to work is to rename the file to some other name and change the docker-compose.yaml

- ./credentials1.json:/app/credentials.json
DLee
  • 7,856
  • 4
  • 19
  • 23
  • Does [this answer](https://stackoverflow.com/a/42260979/4676641) help? TLDR, you should try providing an absolute path. – cam May 18 '21 at 18:10
  • Did Docker create an empty directory for you; does `sudo rmdir credentials.json` work? – David Maze May 18 '21 at 18:36
  • @DavidMaze I tried removing the directory and rerunning docker-compose and it just creates another directory called credentials.json again (even though there is a credentials.json file in path) – DLee May 19 '21 at 23:53
  • @tentative I haven't tried absolute path yet, but providing an absolute path makes it impossible to share the same `docker-compose.yaml` across the team then (diff absolute path for every person)? – DLee May 19 '21 at 23:58
  • The file must exist on the host, as a file and not a directory, before you run `docker-compose up`. (A path relative to the `docker-compose.yml` file should work fine.) – David Maze May 20 '21 at 01:07
  • @DavidMaze Yeah so the issue is that it didn't exist the first time I ran docker-compose. Now Docker somehow "remembers" credentials.json as a directory instead of a file so even if I have a credentials.json file present it won't mount – DLee May 20 '21 at 01:52
  • @DLee You may have determined another solution already but instead of using absolute paths, using `$PWD` or similar has worked to be *somewhat* more portable. – cam May 20 '21 at 05:30

0 Answers0