how to inject host config file to the container in docker for mac preview environment?

521 Views Asked by At

I am using docker environment which is a preview feature of docker for mac.

I’m trying to mount the host’s kube config file to the .kube directory in the dev container.

So I wrote a host path volume mount as shown below

version: "3.9"
services:
    devcontainer:
        build: .
        tty: true
        volumes:
        - ./devcontainer/kube:/.kube

And when I run it in docker for mac environment, the following error log occurs.

 Logs
    Preparing to clone inside a volume
    Installing credential helpers... done
    Cloning into '/code'...
    remote: Enumerating objects: 88, done.
    remote: Counting objects: 100% (88/88), done.remote: Counting objects:  93% (82/88)
    remote: Compressing objects: 100% (58/58), done.remote: Compressing objects:  98% (57/58)remote: Compressing objects:  81% (47/58)
    remote: Total 88 (delta 27), reused 78 (delta 17), pack-reused 0
    Receiving objects: 100% (88/88), 8.46 KiB | 866.00 KiB/s, done.Receiving objects:  80% (71/88)Receiving objects:  71% (63/88)Receiving objects:  53% (47/88)
    Resolving deltas: 100% (27/27), done.
    The Compose file '/var/folders/0z/wq3hw0m17q9cn44d4b1_c3r40000gn/T/volume-dev-container-demo-brave_dewdney/.docker/docker-compose.yaml' is invalid because:
    services.devcontainer.volumes contains unsupported option: 'create_host_path'

Maybe the docker for mac environment is not yet supported to mount the host path volume?

If so, how can I inject the host’s config file?

Can anyone share some good ideas?

1

There are 1 best solutions below

0
Javali On

Try to avoid the "./" in volume paths. Always see paths relatively to the compose file on the local machine and relative to the users home directory in the container. It might be a good idea to use absolute paths in the container. Maybe that helps.