/ bin / sh拒绝获得在生产环境中启动Go服务器的权限 泊坞窗,撰写

I'm running sudo docker-compose on my production server to start up my Go container. I have sudo access in my production server but am not the root user.

error:

go_1     | /bin/sh: ./: Permission denied

docker-compose.yml

go:
    build:
      context: ./api
      args:
        app_env: ${APP_ENV}
    volumes:
      - ./api:/go/src/myproject/api
    expose:
      - "8080"

Go 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.

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.

There was no obvious error message.

Make sure your go code builds and runs on your host, before containerising it.