Home  >  Article  >  Backend Development  >  Docker No such file or directory

Docker No such file or directory

PHPz
PHPzforward
2024-02-09 22:18:09457browse

Docker 没有这样的文件或目录

php editor Xiaoxin will give you the answer: When using Docker, sometimes you will encounter the error message "Docker does not have such a file or directory". This error usually means that Docker cannot find the required file or directory when executing the specified command. There may be many reasons for this error, such as the file or directory does not exist, the path is set incorrectly, etc. There are many ways to solve this problem. You can check whether the file or directory exists, confirm whether the path setting is correct, check whether the Docker image is correct, etc. Hope these methods can help you solve this problem.

Question content

I'm trying to write a very simple and straightforward docker file for a golang application. But for some reason when trying to run the image it gives me this error:

exec /app/servertest: No such file or directory

I can't figure out what's wrong with it, searched for similar questions but nothing solved the problem.

This is my dockerfile:

## Build
FROM golang:1.20 AS build

WORKDIR /tmp/build

COPY go.mod .
COPY go.sum .

RUN go mod download

COPY . .

RUN go build -o ./out/serverTest .

## Deploy
FROM golang:alpine

COPY --from=build /tmp/build/out/serverTest /app/serverTest

EXPOSE 8080

ENTRYPOINT ["/app/serverTest"]

I've tried granting x permissions, using cmd instead of entrypoint, changing names/folders, etc...

Any idea where the problem might be?

Solution

Try building:

CGO_ENABLED=0 go build -o ./out/serverTest .

The above is the detailed content of Docker No such file or directory. For more information, please follow other related articles on the PHP Chinese website!

Statement:
This article is reproduced at:stackoverflow.com. If there is any infringement, please contact admin@php.cn delete