为了账号安全,请及时绑定邮箱和手机立即绑定

Golang docker 容器无法在 Windows Home 上启动

Golang docker 容器无法在 Windows Home 上启动

Go
慕运维8079593 2022-07-11 15:16:57
我正在使用在 Docker 中启用了 WSL 的 Windows Home OS。打印下面的构建消息后docker build .SECURITY WARNING: You are building a Docker image from Windows against a non-    Windows Docker host. All files and directories added to build context will have '-rwxr-    xr-x' permissions. It is recommended to double check and reset permissions for sensitive files and directories.当我尝试运行下面的图像消息时打印docker run 49fee6f5a6bb -ddocker: Error response from daemon: OCI runtime create failed: container_linux.go:349: starting container process caused "exec: \"-d\": executable file not found in $PATH": unknown.Dockerfile 内容如下FROM golang:alpine# Set necessary environmet variables needed for our imageENV GO111MODULE=on \    CGO_ENABLED=0 \    GOOS=linux \    GOARCH=amd64# Move to working directory /buildWORKDIR /build# Copy and download dependency using go modCOPY go.mod .COPY go.sum .RUN go mod download# Copy the code into the containerCOPY . .# Build the applicationRUN go build -o main .# Move to /dist directory as the place for resulting binary folderWORKDIR /dist# Copy binary from build to main folderRUN cp /build/main .# Export necessary portEXPOSE 3000# Command to run when starting the containerCMD ["/dist/main"]
查看完整描述

1 回答

?
LEATH

TA贡献1936条经验 获得超6个赞

问题是命令的顺序(很可能):


docker run -d yourcontainer应该管用


一些不相关的建议:这是对您的 docker 文件的重写(未经测试)。如您所见,它更短,并且使用构建和运行阶段。


FROM alpine:latest构建阶段使用一个更大的容器,里面有golang 、你的代码等。运行容器(例如,仅使用您的代码来强化 linux)。


FROM golang:alpine AS build


WORKDIR /build

ADD . /build


# Depending on the golang version GO111MODULE can be removed as env variable

RUN GOOS=linux GOARCH=amd64 GO111MODULE=on go build -o main 


FROM alpine:latest


# Export necessary port

EXPOSE 3000

# Add  application

WORKDIR /dist

COPY --from=build /build/main /dist/main


查看完整回答
反对 回复 2022-07-11
  • 1 回答
  • 0 关注
  • 84 浏览
慕课专栏
更多

添加回答

举报

0/150
提交
取消
意见反馈 帮助中心 APP下载
官方微信