【问题标题】:How to handle make missing from alpine docker image?如何处理高山 docker 镜像中的缺失?
【发布时间】: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


【解决方案1】:

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

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

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2022-01-14
    • 1970-01-01
    • 2021-07-03
    • 2022-10-15
    • 1970-01-01
    • 2021-06-02
    • 1970-01-01
    • 2017-12-20
    相关资源
    最近更新 更多