Phil
Phil

Reputation: 43

How do I create a docker image from dockerfile and then make a config file available on a volume when running the image from docker-compsose

I am creating a docker container running a python script that collects telemetry. The dockerfile looks like this.

FROM python:3.7-alpine

WORKDIR /app

COPY src/requirements.txt ./

RUN pip install -r requirements.txt

COPY src /app

CMD [ "python", "main.py" ]

inside the folder 'src' is a folder 'config' with 'config.json' saved src/config/config.json

the docker-compose file looks like this

version: '2.2'
services:

   umpmfd:
     container_name: mfdwebsockets
     build: mfdwebsockets
     network_mode: "host"
     restart: always
     volumes:
       - "/home/xtp/config.json:/app/config/config.json"   
     depends_on:
       - influxdb
       - grafana

I want to have the 'config.json' file available on the host machine so I can change the config with out stopping and restarting the container. At the moment I am getting this error.

ERROR: for mfdwebsockets Cannot start service umpmfd: OCI runtime create failed
: container_linux.go:346: starting container process caused "process_linux.go:44
9: container init caused \"rootfs_linux.go:58: mounting \\"/home/xtp/config.jso
n\\" to rootfs \\"/var/lib/docker/overlay2/c5a992a5717f2d510e75056ba38ad4075a0
31e73ca010fef5da8328ad366eaad/merged\\" at \\"/var/lib/docker/overlay2/c5a992a
5717f2d510e75056ba38ad4075a031e73ca010fef5da8328ad366eaad/merged/app/config/conf ig.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

ERROR: for umpmfd Cannot start service umpmfd: OCI runtime create failed: conta
iner_linux.go:346: starting container process caused "process_linux.go:449: cont
ainer init caused \"rootfs_linux.go:58: mounting \\"/home/xtp/config.json\\" t
o rootfs \\"/var/lib/docker/overlay2/c5a992a5717f2d510e75056ba38ad4075a031e73ca 010fef5da8328ad366eaad/merged\\" at \\"/var/lib/docker/overlay2/c5a992a5717f2d
510e75056ba38ad4075a031e73ca010fef5da8328ad366eaad/merged/app/config/config.json \\" caused \\"not a directory\\"\"": unknown: Are you trying to mount a direc
tory onto a file (or vice-versa)? Check if the specified host path exists and is
the expected type

What do I need to change to get this config.json file available as a volume on the host machine?

Upvotes: 1

Views: 859

Answers (1)

makozaki
makozaki

Reputation: 4366

Are you trying to mount a directory onto a file (or vice-versa)?

This is exactly what error message suggests.

Mount directories instead of files.

  volumes:
    - "/home/xtp:/app/config" 

Upvotes: 1

Related Questions