docker - 如何处理 make missing from alpine docker imag

我的应用程序上有 Makefiles,所有命令都在 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

最佳答案

如果您希望避免将 make 的所有依赖项添加到您的 alpine 图像中并保持运输容器的尺寸较小:

  • 在您的容器外构建您的二进制文件,并仅将可交付的二进制文件复制到您的 alpine 容器
  • 在一个普通的 golang 容器中构建你的二进制文件,然后将二进制文件复制到一个小型可运输的 alpine 容器中
  • 你可以给https://github.com/go-task/task尝试一下,与在您的 Alpine 容器中安装 make 并将您的 make 文件替换为任务文件相比,不需要太多依赖项。

关于docker - 如何处理 make missing from alpine docker image?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/62163126/

相关文章:

python - psutil.AccessDenied : psutil. AccessDenie

graphql-java - 读取通过 G​​raphQL Java 中的变量传递的字段参数

reactjs - React Rich Text Editor 真的可以在移动设备上运行吗?

javascript - 创建 React 应用程序 + React lazy + Absolute

ethereum - 返回错误 : The method web3_clientVersion do

r - 在创建列表 tibble 列时在 "mutation"中使用 dplyr::sym() 会导

docker - 无法加载动态库 'libcuda.so.1'; dlerror : libcuda

c# - 如何评估包含局部变量名称的字符串作为 C# 中的代码

google-cloud-functions - GCP Console : console. lo

python - 在 tensorflow 2.0 中保存和加载模型