0

我在构建 go proyect 时遇到问题,我使用 golang:alpine 构建并将结果复制到 oraclelinux:7-slim 问题是当我执行 docker 映像时结果是错误

"standard_init_linux.go:211: exec user process caused "no such file or directory"".

我尝试通过示例“FROM golang:1.14 as builder”使用其他基础镜像构建并在 oraclelinux:7-slim 中执行,结果令人满意。

我需要在 oraclelinux:7-slim 中执行,因为需要使用 Oracle Instant 客户端连接数据库。

我想用 Alpine 构建,因为 golang:1.14 非常重。

附上dockerfile

# Start from golang base image
FROM golang:alpine as builder

RUN apk update && apk add --no-cache git && \
    apk add build-base

# Set the current working directory inside the container
WORKDIR /app

# Copy go mod and sum files
COPY go.mod go.sum ./

# Download all dependencies. Dependencies will be cached if the go.mod and the go.sum files are not changed 
RUN go mod download 

# Copy the source from the current directory to the working Directory inside the container 
COPY . .

# Build the Go app
RUN CGO_ENABLED=1 GOOS=linux GOARCH=amd64 go build -a -installsuffix cgo -o main .

# Start a new stage from scratch
FROM oraclelinux:7-slim

ARG release=19
ARG update=6

# Install instant client
RUN yum -y update && \
    yum -y install oracle-release-el7 && yum-config-manager --enable ol7_oracle_instantclient && \
    yum -y install oracle-instantclient${release}.${update}-basiclite && \    
    rm -rf /var/cache/yum

ENV LANG=C.UTF-8

# Copy the Pre-built binary file from the previous stage
WORKDIR /root/

COPY --from=builder /app/main .
COPY --from=builder /app/.env .

# Expose port 8080 to the outside world
EXPOSE 8080

#Command to run the executable
ENTRYPOINT ["./main"]
4

0 回答 0