我的应用程序上有 Makefile,所有命令都在 Makefile 上 我把它放在 Dockerfile 上:
# start from the latest golang base image
FROM golang:alpine
RUN apk update && apk add --no-cache gcc && apk add --no-cache libc-dev
# Set the current working Directory inside the container
WORKDIR /app
# Copy go mod and sum files
COPY go.mod go.sum ./
# Download all dependencies. they will be cached of the go.mod and go.sum files are not changed
RUN go mod download
# Copy the source from the current directory to the WORKDIR inisde the container
COPY . .
# Build the Go app
RUN go build .
# Exporse port 3000 or 8000 to the outisde world
EXPOSE 3000
# Command to run the executable
CMD ["make", "-C", "scripts", "test" ]
CMD ["make", "-C", "scripts", "prod" ]
并且得到了
docker: Error response from daemon: OCI runtime create failed:
container_linux.go:349: starting container process caused "exec:
\"make\": executable file not found in $PATH": unknown.
可以在 Docker 中运行
make -c scripts test
吗?如何正确地在 Docker 中使用此命令?
在
dockerfile
我跑步golang:alpine
如果您添加了
RUN apk add --no-cache make
但仍然存在问题,请将其也添加到您的 DockerFile 中:
RUN apk add g++
Alpine 图像是轻量级的,并且其中没有实用程序,添加 g++ 可以解决这个问题。您可以使用
which make
命令检查输出,对我来说它返回 /usr/bin/make
参考:https://mroldan.medium.com/alpine-sh-make-not-found-1e87ab87c56
如果您希望避免将 make 的所有依赖项添加到 alpine 映像并保持集装箱尺寸较小: