【发布时间】:2020-06-02 23:53:21
【问题描述】:
我的应用程序上有 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
【问题讨论】:
-
您的 docker 映像中可能没有安装
make实用程序。如果你想在你的容器中运行 make inside,你必须在你的镜像中安装make程序。 -
你知道如何在 alphine 中安装它吗?
-
在您的 Dockerfile 中添加
apk add --no-cache make有帮助吗? -
是的,它工作正常,当我在 alpine 上添加软件包时,我在 docker 上有一个巨大的图像,我应该在主 Linux 上安装这些必需品软件包吗?而不是用
apk安装它 -
使用multi-stage docker build。它专为使用“臃肿”的开发映像进行构建/编译而设计 - 然后最后阶段可以仅包含这些工件(没有所有工具“膨胀”)。
标签: docker go makefile command-line dockerfile