duanhanzi8328 2018-07-22 10:10
浏览 141
已采纳

docker-compose通过dockerfiles运行2个服务,main.go找不到任务“ phx.server”:没有这样的文件或目录

I have an issue running my docker-compose.yml file with 4 services. They are my go microservice, phoenix web server, mongodb and redis images.

I specified in both my phoenix and golang dockerfiles to change working directory before running both services. I currently get the following errors when I do docker-compose up.

The task "phx.server" could not be found main.go: no such file or directory

Here is my Dockerfile.go.development:

# base image elixer to start with
FROM golang:latest

# create app folder
RUN mkdir /goApp
COPY ./genesys-api /goApp
WORKDIR /goApp/cmd/genesys-server

# install dependencies
RUN go get gopkg.in/redis.v2
RUN go get github.com/gorilla/handlers
RUN go get github.com/dgrijalva/jwt-go
RUN go get github.com/gorilla/context
RUN go get github.com/gorilla/mux
RUN go get gopkg.in/mgo.v2/bson
RUN go get github.com/graphql-go/graphql

# run phoenix in *dev* mode on port 8080
CMD go run main.go

Here is my Dockerfile.phoenix.development:

# base image elixer to start with
FROM elixir:1.6

# install hex package manager
RUN mix local.hex --force
RUN mix local.rebar --force

# install the latest phoenix 
RUN mix archive.install https://github.com/phoenixframework/archives/raw/master/phx_new.ez --force

# create app folder
RUN mkdir /app
COPY ./my_app /app
WORKDIR /app

# install dependencies
RUN mix deps.get

# run phoenix in *dev* mode on port 4000
CMD mix phx.server

Here is my docker-compose.yml file:

version: '3.6'
services:
  go:
    build:
      context: .
      dockerfile: Dockerfile.go.development
    ports:
      - 8080:8080
    volumes:
      - .:/goApp
    depends_on:
      - db
      - redis
  phoenix:
    # tell docker-compose which Dockerfile it needs to build
    build:
      context: .
      dockerfile: Dockerfile.phoenix.development
    # map the port of phoenix to the local dev port
    ports:
      - 4000:4000
    # mount the code folder inside the running container for easy development
    volumes:
      - .:/app
    # make sure we start mongodb when we start this service
    # links:
    #   - db
    depends_on:
      - db
      - redis
    environment:
      GOOGLE_CLIENT_ID: ${GOOGLE_CLIENT_ID}
      GOOGLE_CLIENT_SECRET: ${GOOGLE_CLIENT_SECRET}
      FACEBOOK_CLIENT_ID: ${FACEBOOK_CLIENT_ID}
      FACEBOOK_CLIENT_SECRET: ${FACEBOOK_CLIENT_SECRET}
  db:
    container_name: db
    image: mongo:latest
    volumes:
      - ./data/db:/data/db
    ports:
      - 27017:27017
  redis:
    container_name: redis
    image: redis:latest
    ports:
      - "6379:6379"
    volumes:
      - ./data/redis:/data/redis
    entrypoint: redis-server
    restart: always

</div>
  • 写回答

1条回答 默认 最新

  • duanjiu1003 2018-07-22 12:36
    关注

    For the error related to go microservice, Since the go binary is not found in PATH, you may need to set the GOPATH env variable via your docker file for go:

    export GOPATH=
    
    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论

报告相同问题?

悬赏问题

  • ¥15 逻辑谓词和消解原理的运用
  • ¥15 三菱伺服电机按启动按钮有使能但不动作
  • ¥15 js,页面2返回页面1时定位进入的设备
  • ¥200 关于#c++#的问题,请各位专家解答!网站的邀请码
  • ¥50 导入文件到网吧的电脑并且在重启之后不会被恢复
  • ¥15 (希望可以解决问题)ma和mb文件无法正常打开,打开后是空白,但是有正常内存占用,但可以在打开Maya应用程序后打开场景ma和mb格式。
  • ¥20 ML307A在使用AT命令连接EMQX平台的MQTT时被拒绝
  • ¥20 腾讯企业邮箱邮件可以恢复么
  • ¥15 有人知道怎么将自己的迁移策略布到edgecloudsim上使用吗?
  • ¥15 错误 LNK2001 无法解析的外部符号