gpt4 book ai didi

docker - 无法读取容器中的文件

转载 作者:行者123 更新时间:2023-12-02 20:04:29 25 4
gpt4 key购买 nike

这是我的docker-compose.yml :

version: '3.3'

services:
etcd:
container_name: 'etcd'
image: 'quay.io/coreos/etcd'
command: >
etcd -name etcd
-advertise-client-urls http://127.0.0.1:2379,http://127.0.0.1:4001
-listen-client-urls http://0.0.0.0:2379,http://0.0.0.0:4001
-initial-advertise-peer-urls http://127.0.0.1:2380
-listen-peer-urls http://0.0.0.0:2380
healthcheck:
test: ["CMD", "curl", "-f", "http://etcd:2379/version"]
interval: 30s
timeout: 10s
retries: 5
networks:
robotrader:

kontrol:
container_name: 'kontrol'
env_file: 'variables.env'
build:
context: '.'
dockerfile: 'Dockerfile'
volumes:
- '/certs:/certs'
ports:
- '6000:6000'
depends_on:
- 'etcd'
networks:
robotrader:

mongo:
container_name: 'mongo'
image: 'mongo:latest'
ports:
- '27017:27017'
volumes:
- '/var/lib/mongodb:/var/lib/mongodb'
networks:
robotrader:

networks:
robotrader:

...这里是 Dockerfile用于 build kontrol :
FROM golang:1.8.3 as builder
RUN go get -u github.com/golang/dep/cmd/dep
RUN go get -d github.com/koding/kite
WORKDIR ${GOPATH}/src/github.com/koding/kite
RUN ${GOPATH}/bin/dep ensure
RUN go install ./kontrol/kontrol
RUN mv ${GOPATH}/bin/kontrol /tmp

FROM busybox
ENV APP_HOME /opt/robotrader
RUN mkdir -p ${APP_HOME}
RUN mkdir /certs
WORKDIR ${APP_HOME}
COPY --from=builder /tmp/kontrol .
ENTRYPOINT ["./kontrol", "-initial"]
CMD ["./kontrol"]

最后当我发出命令时......
sudo -E docker-compose -f docker-compose.yaml up

... 两者 etcdmongo启动成功,而 kontrol失败并出现以下错误:
kontrol    | 2018/06/21 20:11:14 cannot read public key file: open "/certs/key_pub.pem": no such file or directory

如果我登录到容器..
sudo docker run -it --rm --name j3d-test --entrypoint sh j3d

...并查看文件夹 /certs ,文件在那里:
ls -la /certs
-rw-r--r--. 1 root root 1679 Jun 21 21:11 key.pem
-rw-r--r--. 1 root root 451 Jun 21 21:11 key_pub.pem

我错过了什么?

最佳答案

当您运行此命令时:

sudo docker run -it --rm --name j3d-test --entrypoint sh j3d

您不是“登录到容器”。您正在创建一个新容器,并且正在查看 /certs 的内容在底层图像上。但是,在您的 docker-compose.yaml你有:
kontrol:
[...]
volumes:
- '/certs:/certs'
[...]

您已从 $PWD/certs 配置绑定(bind)挂载到 /certs容器中的目录。您本地的 certs 是什么?目录
包含?

关于docker - 无法读取容器中的文件,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/50977190/

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