Warning: file_get_contents(/data/phpspider/zhask/data//catemap/7/sqlite/3.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/8/svg/2.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
CGO_Enabled=1所需的在Alpine Docker容器中使用SQLite构建Go二进制文件_Docker_Sqlite_Go_Alpine_Go Gorm - Fatal编程技术网

CGO_Enabled=1所需的在Alpine Docker容器中使用SQLite构建Go二进制文件

CGO_Enabled=1所需的在Alpine Docker容器中使用SQLite构建Go二进制文件,docker,sqlite,go,alpine,go-gorm,Docker,Sqlite,Go,Alpine,Go Gorm,我试图编译一个Alpine Go容器,它使用和它的内存数据库。这取决于是否启用CGO。我的二进制文件使用go build.生成并执行良好,但在运行我的docker映像(docker build.后接docker run$imagename)时,我收到错误消息: standard_init_linux.go:219: exec user process caused: no such file or directory 我正在Windows 10 64位上构建。我已经安装了gcc。C:\TDM-

我试图编译一个Alpine Go容器,它使用和它的内存数据库。这取决于是否启用CGO。我的二进制文件使用
go build.
生成并执行良好,但在运行我的docker映像(
docker build.
后接
docker run$imagename
)时,我收到错误消息:

standard_init_linux.go:219: exec user process caused: no such file or directory
我正在Windows 10 64位上构建。我已经安装了gcc。
C:\TDM-GCC-64\bin
C:\cygwin64\bin
都在我的$env:path中。我已将包中所有文件的行尾更改为Linux样式(LF)

我的docker文件如下:

FROM golang:1.16.4-alpine AS builder

RUN apk update \
    && apk add --no-cache git \
    && apk add --no-cache ca-certificates \
    && apk add --update gcc musl-dev \
    && update-ca-certificates

# Create a user so that the image doens't run as root
RUN adduser \
    --disabled-password \
    --gecos "" \
    --home "/nonexistent" \
    --shell "/sbin/nologin" \
    --no-create-home \
    --uid "100001" \
    "appuser"

# Set the working directory inside the container.
WORKDIR $GOPATH/src/app

# Copy all files from the current directory to the working directory
COPY . .

# Fetch dependencies.
RUN go get -u -d -v

# Go build the binary, specifying the final OS and architecture we're looking for
RUN GOOS=linux CGO_ENABLED=1 GOARCH=amd64 go build -ldflags="-w -s" -o /go/bin/app -tags timetzdata

FROM scratch

# Import the user and group files from the builder.
COPY --from=builder /etc/passwd /etc/passwd
COPY --from=builder /etc/group /etc/group
COPY --from=builder /etc/ssl/certs/ca-certificates.crt /etc/ssl/certs/

# Copy our static executable.
COPY --from=builder /go/bin/app/go/bin/app

# Use the user that we've just created, one that isn't root
USER appuser:appuser

ENTRYPOINT ["/go/bin/app"]
你能帮我理解为什么我的docker图像无法运行吗

如果它有任何值,打开DB的Go代码行是这样的。因为这可以在本地使用Go build或使用
Go run。
但我认为这与此无关

db, err := gorm.Open(sqlite.Open("file::memory:?cache=shared"), &gorm.Config{})

我认为这是一个简单的文件格式问题。您可以根据下面的答案解决此问题


谢谢你的建议!不幸的是,我已经将行尾更改为LF,因此这似乎不是问题所在。请检查文件路径或路径引用。您可以在任何Linux系统上运行dos2unix命令。如果您没有访问Linux系统的权限,可以使用dos2unix.exe附带的Git Bash for Windows。然后,您的命令可能如下所示:
dos2unix.exe您的文件.sh