douji7399
douji7399
2017-09-27 20:08
浏览 68

/ 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?

  • 点赞
  • 写回答
  • 关注问题
  • 收藏
  • 邀请回答

2条回答 默认 最新

  • doushui5587
    doushui5587 2017-09-27 20:32
    已采纳

    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
    
    点赞 评论
  • dongpouda6700
    dongpouda6700 2019-07-26 08:20

    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.

    点赞 评论

相关推荐