[英]Getting permission denied for /bin/sh to start Go server in production | docker-compose
I'm running sudo docker-compose
on my production server to start up my Go container.我正在我的生产服务器上运行
sudo docker-compose
来启动我的 Go 容器。 I have sudo access in my production server but am not the root user.我在我的生产服务器中有 sudo 访问权限,但不是 root 用户。
error:错误:
go_1 | /bin/sh: ./: Permission denied
docker-compose.yml docker-compose.yml
go:
build:
context: ./api
args:
app_env: ${APP_ENV}
volumes:
- ./api:/go/src/myproject/api
expose:
- "8080"
Go Dockerfile转到 Dockerfile
From golang:1.8.3-alpine3.6
RUN apk update && \
apk add \
bash \
build-base \
curl \
make \
git \
&& rm -rf /var/cache/apk/*
ARG app_env
ENV APP_ENV $app_env
COPY . /go/src/myproject/api
WORKDIR /go/src/myproject/api
CMD if [ ${APP_ENV} = prod ]; \
then \
./; \
else \
go get github.com/pilu/fresh && \
fresh; \
fi
EXPOSE 8080
Any ideas on how to resolve this?关于如何解决这个问题的任何想法?
You need to build your go program and then tell Docker, with CMD
, to use the resulting binary as the default executable.您需要构建您的 go 程序,然后使用
CMD
告诉 Docker 使用生成的二进制文件作为默认可执行文件。
Try something like this:尝试这样的事情:
From golang:1.8.3-alpine3.6
RUN apk update && \
apk add \
bash \
build-base \
curl \
make \
git \
&& rm -rf /var/cache/apk/*
ARG app_env
ENV APP_ENV $app_env
COPY . /go/src/myproject/api
WORKDIR /go/src/myproject/api
RUN go get ./
RUN go build
CMD if [ ${APP_ENV} = prod ]; \
then \
api; \
else \
go get github.com/pilu/fresh && \
fresh; \
fi
EXPOSE 8080
If you haven't named the package containing the main function as "main", I found with multi-stage builds it was building but it wasn't a binary.如果您还没有将包含 main 函数的包命名为“main”,我发现它在多阶段构建中正在构建,但它不是二进制文件。
There was no obvious error message.没有明显的错误信息。
Make sure your go code builds and runs on your host, before containerising it.在容器化之前,请确保您的 go 代码在您的主机上构建并运行。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.