Postgres,Go Docker编写wait-for-it.sh没有此类文件或目录 [英] Postgres, Go Docker compose wait-for-it.sh no such file or directory

查看:221
本文介绍了Postgres,Go Docker编写wait-for-it.sh没有此类文件或目录的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

曾经花了将近两天的时间。



我是Docker和Docker Compose的新手,并试图在EC2实例上运行我的映像运行Postgres和Go。当我运行docker-compose up时, db 服务成功运行,但 app 服务未成功运行。



当我尝试使用以下命令分别运行服务时:



docker-compose up db 一切都很好



然后运行:



docker-compose up app 我得到...

  app_1 | wait-it-sh.sh:等待db:5432 15秒
app_1 | wait-for-it.sh:db:5432在0秒后可用
app_1 | ./wait-for-it.sh:第174行:/go/src/github.com/MY_USERNAME/MY_APP_DIR/EXECUTABLE:没有这样的文件或目录
some_name-golang_app_1退出,代码为127

Dockerfile备用:

 从golang:最新

EXPOSE 8080

WORKDIR /go/src/github.com/MY_USERNAME/MY_APP_DIR
添加。 /go/src/github.com/MY_USERNAME/MY_APP_DIR

#安装当前项目的所有依赖项。
RUN go -v
RUN go build

docker-compose.yml

 版本: 3 
服务:
db:
图片:postgres
环境:
POSTGRES_DB:dbname
POSTGRES_USER:miller
POSTGRES_PASSWORD:miller
端口:
- 6000:5432
应用程序:
构建:
上下文:。
dockerfile:Dockerfile备用
命令:[ ./wait-for-it.sh, db:5432,-, ./EXECUTABLE]
卷:
-。:/ go / src / github.com / gregpmillr / volume
端口:
- 80:8080
取决于:
-db
链接:
-db

如果我运行 docker run -it --rm MY_USERNAME / custom-go-image ,然后我确实看到了 EXECUTABLE 文件,并且可以运行 ./ EXECUTABLE 成功...好吧,我没有出现这样的主机错误,但可以肯定的是,因为我没有同时使用docker-compose启动它们。 / p>

有人对这个问题有想法吗?提示/资源会很棒。我一直在努力探索谷歌搜索问题,却一无所获。像往常一样,我可能缺少了一些东西。谢谢!!!!



我希望先运行postgres(现在可以正常运行),然后运行连接到postgres的go服务器。



UPDATE 1



命令:[ sh, -c, cd /go/src/github.com/gregpmillr/volume&& ls -l]



将提供以下输出:

  db_1 | 2018-08-19 11:19:48.828 UTC [1]日志:侦听IPv4地址 0.0.0.0,端口5432 
db_1 | 2018-08-19 11:19:48.828 UTC [1]日志:侦听IPv6地址 ::,端口5432
db_1 | 2018-08-19 11:19:48.831 UTC [1]日志:在Unix套接字上监听 /var/run/postgresql/.s.PGSQL.5432
db_1 | 2018-08-19 11:19:48.857 UTC [21]日志:数据库系统已于2018-08-19 01:03:35 UTC
db_1 |关闭。 2018-08-19 11:19:48.880 UTC [1]日志:数据库系统已准备好接受连接
app_1 |总计36
app_1 | -rw-rw-r-- 1 1000 1000 238 Aug 19 11:19 Dockerfile-alternate
app_1 | -rw-rw-r-- 1 1000 1000 260 Aug 17 19:24 Dockerrun.aws.json
app_1 | -rw-rw-r-- 1 1000 1000 62 Aug 17 18:56 README.md
app_1 | drwxrwxr-x 8 1000 1000 4096 8月17日19:00 app
app_1 | drwxrwxr-x 2 1000 1000 4096 8月17日19:34配置
app_1 | -rwxrwxr-x 1 1000 1000 708 8月17日19:48 deploy.sh
app_1 | -rw-rw-r-- 1 1000 1000 548 Aug 19 11:19 docker-compose.yml
app_1 | -rw-rw-r-- 1 1000 1000 1188 8月17日19:00 main.go
app_1 | -rwxrwxr-x 1 1000 1000 4079 8月17日19:00 wait-for-it.sh
app_1退出,代码为0

Dockerrun文件是不必要的,因为我没有使用弹性beantalk atm。



UPDATE 2
解决了。查看已接受的答案。更具体地说,请参见 https://docs.docker.com/storage/ https://docs.docker.com/storage/volumes/ 了解有关卷的更多信息。谢谢您的帮助!

解决方案

您已将go源代码添加到图像中,并将其编译为图像的一部分。您的构建。然后,通过包含以下内容,用包含源代码的卷(显然没有编译的二进制文件)覆盖同一路径:

  volumes :
-。:/ go / src / github.com / gregpmillr / Tranquility-Online-Golang

您要么需要该卷中的已编译二进制文件,要么跳过该卷到容器中的安装,因为它阻止了对映像文件的访问。


Been racking my head about this one for almost two days.

I'm new to Docker and Docker Compose, and trying to run my image on an EC2 instance running Postgres and Go. When I run docker-compose up, the db service runs successfully, but not the app service.

When I try to run the services separately using:

docker-compose up db all is good

then run:

docker-compose up app I get...

app_1  | wait-for-it.sh: waiting 15 seconds for db:5432
app_1  | wait-for-it.sh: db:5432 is available after 0 seconds
app_1  | ./wait-for-it.sh: line 174: /go/src/github.com/MY_USERNAME/MY_APP_DIR/EXECUTABLE: No such file or directory
some_name-golang_app_1 exited with code 127

Dockerfile-alternate:

FROM  golang:latest

EXPOSE 8080

WORKDIR /go/src/github.com/MY_USERNAME/MY_APP_DIR
ADD . /go/src/github.com/MY_USERNAME/MY_APP_DIR

# Install all dependencies of the current project.
RUN go get -v
RUN go build

docker-compose.yml

version: '3'
services:
  db:
      image: postgres
      environment:
          POSTGRES_DB: dbname
          POSTGRES_USER: miller
          POSTGRES_PASSWORD: miller
      ports:
        - "6000:5432"
  app:
    build:
      context: .
      dockerfile: Dockerfile-alternate
    command: ["./wait-for-it.sh", "db:5432", "--", "./EXECUTABLE"]
    volumes:
      - .:/go/src/github.com/gregpmillr/volume
    ports:
      - "80:8080"
    depends_on:
        - db
    links:
        - db

Interestingly enough, if I run docker run -it --rm MY_USERNAME/custom-go-image then I actually do see the EXECUTABLE file, and can run ./EXECUTABLE successfully... Well sort-of, I get a no such host error but pretty sure that's because I'm not starting them at the same time using docker-compose.

Any thought on this issue? Tips / resources would be great. I've been heading down rabbit holes of googling issues and leading nowhere. It's probably something small that I'm missing as per usual. Thanks!!

I'm looking to run postgres first (works correctly now), then run the go server which connects to postgres.

UPDATE 1

command: [ "sh", "-c", "cd /go/src/github.com/gregpmillr/volume && ls -l" ]

will give the following output:

db_1   | 2018-08-19 11:19:48.828 UTC [1] LOG:  listening on IPv4 address "0.0.0.0", port 5432
db_1   | 2018-08-19 11:19:48.828 UTC [1] LOG:  listening on IPv6 address "::", port 5432
db_1   | 2018-08-19 11:19:48.831 UTC [1] LOG:  listening on Unix socket "/var/run/postgresql/.s.PGSQL.5432"
db_1   | 2018-08-19 11:19:48.857 UTC [21] LOG:  database system was shut down at 2018-08-19 01:03:35 UTC
db_1   | 2018-08-19 11:19:48.880 UTC [1] LOG:  database system is ready to accept connections
app_1  | total 36
app_1  | -rw-rw-r-- 1 1000 1000  238 Aug 19 11:19 Dockerfile-alternate
app_1  | -rw-rw-r-- 1 1000 1000  260 Aug 17 19:24 Dockerrun.aws.json
app_1  | -rw-rw-r-- 1 1000 1000   62 Aug 17 18:56 README.md
app_1  | drwxrwxr-x 8 1000 1000 4096 Aug 17 19:00 app
app_1  | drwxrwxr-x 2 1000 1000 4096 Aug 17 19:34 config
app_1  | -rwxrwxr-x 1 1000 1000  708 Aug 17 19:48 deploy.sh
app_1  | -rw-rw-r-- 1 1000 1000  548 Aug 19 11:19 docker-compose.yml
app_1  | -rw-rw-r-- 1 1000 1000 1188 Aug 17 19:00 main.go
app_1  | -rwxrwxr-x 1 1000 1000 4079 Aug 17 19:00 wait-for-it.sh
app_1 exited with code 0

Dockerrun file is unnecessary as I'm not using elastic beanstalk atm.

UPDATE 2 Solved. See accepted answer. More specifically, see https://docs.docker.com/storage/ and https://docs.docker.com/storage/volumes/ for more info on Volumes. Thanks for the help!

解决方案

You've added the go source code into your image and compiled it inside the image as part of your build. Then you overlaid that same path with a volume containing your source code (apparently without a compiled binary) by including the following:

volumes:
  - .:/go/src/github.com/gregpmillr/Tranquility-Online-Golang

You either need the compiled binary in that volume, or skip mounting the volume into the container since it is blocking access to the files in your image.

这篇关于Postgres,Go Docker编写wait-for-it.sh没有此类文件或目录的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
相关文章
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆