Create docker container Times no such file or directory: unknown

system environment centos7
Project directory my_test_server/api
where Dockerfile

FROM golang:latest

WORKDIR $GOPATH/src/my_test_server/api
COPY . $GOPATH/src/my_test_server/api
RUN  go build .

EXPOSE 7777
ENTRYPOINT ["./api"]

build image succeeded, but in
docker run-v / home/project/my_test_server/api:/go/src/my_test_server/api
error

Error response from daemon: OCI runtime create failed: container_linux.go:348: starting container process caused "exec: \"./api\": stat ./api: no such file or directory": unknown.

ask questions above humbly < del > Thank you < / del >

PS can only be compiled first, and then run in docker container

.
Dec.20,2021

if you want to mount as a directory, / go/src/zy_consumer_server/api must be created in the image beforehand.
what you created in Dockerfile is $GOPATH/src/my_test_server/api . Is it wrong to mount another one?


because when starting as an entry point, docker will map the directory in the container to local. If there are files in the container, Will be deleted if you have a file under your local api. Therefore, it is best not to make the files at the entry point into a mapping directory.

Menu