I try build online compiler c++. This my dockerfile
:
FROM alpine:latest
COPY . .
RUN apk update
&& apk add build-base
&& apk add g++
RUN [ "chmod","+x", "./judge.sh" ]
ENTRYPOINT [ "./judge.sh" ]
I write judge.sh
file this for show what happening:
#!/bin/sh
echo 1
After successfully building image I run this command: docker run -v $(pwd)/judge.sh test-judge
or docker run test-judge
this command, I get this same error:
docker: Error response from daemon: cannot mount volume over existing file, file exists /var/lib/docker/overlay2/b064ecb567a905938f02177dcc73f8532556d24abb87dc10cd491cb5406548c6/merged/judge.sh
How to fix this error? And how to use judge.sh
file in docker volume?
2
Answers
You have
COPY . .
instruction in your dockerfile, which will copy all the contents where dockerfile is located, inside your image, including file judge.sh.Now, when you run a container, it already has this judge.sh file inside it and you are also trying to mount the same file from outside the container and hence you are getting the error of
Any reason why you need to both copy AND mount ?
volumes and mounts are used on directories that contain files, not a single file.
in the Dockerfile, set the workdir before copying
to run the copied judge.sh:
docker run test
ordocker run test ./judge.sh
to bind a directory with custom scripts
docker run -it -v $(pwd):/app test ./judge.sh
ordocker run -it -v $(pwd):/app test ./custom_script.sh