Reputation: 3
I am writing a dockerfile
for my go
application. Here, I need a file which is located in /home/saivamsi/.kube/config
on my local machine. If I am directly using it in the code, it is showing an error that no file or directory is found. So, i started using volumes for that but I don't know where it went wrong , I am unable to use that file in my code.
FROM golang:1.14.0
ENV HOMEABC=/home/saivamsi
WORKDIR /go/src/bifrost
VOLUME src="${HOMEABC}/.kube/config",target="/go/src/bifrost/config"
COPY --chown=bbadmin:bbadmin . /go/src/bifrost
COPY go.mod go.sum ./
RUN go mod download
RUN go build -o main .
#EXPOSE 8001
CMD ["./main"]
# CMD ["tail", "-f", "/dev/null"]
Upvotes: 0
Views: 586
Reputation: 11
The use of the VOLUME
instruction in your Dockerfile is incorrect. The Dockerfile reference for VOLUME states:
The host directory is declared at container run-time: The host directory (the mountpoint) is, by its nature, host-dependent. This is to preserve image portability, since a given host directory can’t be guaranteed to be available on all hosts. For this reason, you can’t mount a host directory from within the Dockerfile. The VOLUME instruction does not support specifying a host-dir parameter. You must specify the mountpoint when you create or run the container.
To mount your $HOME/.kube
directory on the host to the container at runtime, you would specify --volume
or -v
in your docker run
command.
For example, you would first remove the VOLUME
instruction from your Dockerfile. Then, you would run something like the following:
docker run --volume $HOME/.kube:/go/src/bifrost <image name>
This will mount your $HOME/.kube
directory on your host to the /go/src/bifrost
directory within the running container. The config file would then be present at /go/src/bifrost/config
at runtime.
NOTE: This solution only works while the kube config file is present on the host on which you are running your container. To include the configuration file in the image itself, it must exist in the Docker build context.
Upvotes: 1