无法读取容器中的文件

时间:2018-06-21 20:47:21

标签: docker docker-compose dockerfile

这是我的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的{​​{1}}:

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 etcd均成功启动,而mongo失败并出现以下错误:

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

我想念什么?

1 个答案:

答案 0 :(得分:0)

运行此命令时:

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

您不是在“登录到容器”。您正在创建一个 new 容器,并在基础图像上查看/certs的内容。但是,您的docker-compose.yaml中有:

kontrol:
  [...]
  volumes:
    - '/certs:/certs'
  [...]

您已将绑定安装从$PWD/certs/certs上 容器中的目录。您的本地certs目录是什么 包含吗?