gpt4 book ai didi

docker-compose 使用 dockerfiles 运行 2 个服务,找不到任务 "phx.server",main.go : no such file or directory

转载 作者:数据小太阳 更新时间:2023-10-29 03:11:11 26 4
gpt4 key购买 nike

我在运行包含 4 个服务的 docker-compose.yml 文件时遇到问题。它们是我的 go 微服务、phoenix web 服务器、mongodb 和 redis 镜像。

我在我的 phoenix 和 golang dockerfiles 中指定在运行这两个服务之前更改工作目录。我目前在执行 docker-compose up 时遇到以下错误。

找不到任务“phx.server”main.go: 没有那个文件或目录

这是我的 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

这是我的 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

这是我的 docker-compose.yml 文件:

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

最佳答案

对于与 go 微服务相关的错误,由于在 PATH 中找不到 go 二进制文件,您可能需要通过 docker 文件为 go 设置 GOPATH env 变量:

export GOPATH=

关于docker-compose 使用 dockerfiles 运行 2 个服务,找不到任务 "phx.server",main.go : no such file or directory,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/51464045/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com