簡體   English   中英

如何處理高山 docker 圖像中的缺失?

[英]How to handle make missing from alpine docker image?

我的應用程序上有 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

如果您希望避免將 make 的所有依賴項添加到您的 alpine 映像中並保持運輸容器的尺寸較小:

  • 在您的容器外構建您的二進制文件,並僅將可交付的二進制文件復制到您的 alpine 容器
  • 在普通的 golang 容器中構建您的二進制文件,然后將二進制文件復制到一個可運輸的小型 alpine 容器中
  • 你可以試試https://github.com/go-task/task ,與在你的 alpine 容器中安裝 make 並用任務文件替換你的 make 文件相比,不需要太多的依賴項。

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM