简体   繁体   English

Docker无法找到文件

[英]Docker Unable to find file

I'm trying to build and run a docker image with docker-compose up However, I get the error can't open /config/config.template: no such file 我正在尝试使用docker-compose up来构建和运行docker映像,但是我得到了can't open /config/config.template: no such file的错误can't open /config/config.template: no such file

My Dockerfile is as follows: 我的Dockerfile如下:

FROM quay.io/coreos/clair-git
COPY config.template /config/config.template

#Set Defaults
ENV USER=clair PASSWORD=johnnybegood INSTANCE_NAME=postgres PORT=5432

RUN apk add gettext
CMD envsubst < /config/config.template > /config/config.yaml && rm -f /config/config.template && exec /clair -config=/config/config.yaml
ENTRYPOINT []

when adding the line RUN ls -la /config/ the following is returned after running docker-compose up --build : 当添加RUN ls -la /config/行时,在运行docker-compose up --build后返回以下内容:

drwxr-xr-x    2 root     root          4096 Sep 16 06:46 .
drwxr-xr-x    1 root     root          4096 Sep 16 06:46 ..
-rw-rw-r--    1 root     root           306 Sep  6 05:55 config.template

Here is the error: 这是错误:

clair_1_9345a64befa1 | /bin/sh: can't open /config/config.template: no such file

I've tried changing line endings and checking the docker version. 我试过更改行尾并检查docker版本。 It seems to work on a different machine running a different OS. 它似乎可以在运行不同操作系统的不同计算机上运行。

I'm using Ubuntu 18.04 and have docker version docker-compose version 1.23.1, build b02f1306 我正在使用Ubuntu 18.04,并且具有docker-compose version 1.23.1, build b02f1306

My docker-compose.yml file: 我的docker-compose.yml文件:

version: '3.3'

services:
  clair:
    build:
      context: clair/
      dockerfile: Dockerfile
    environment:
      - PASSWORD=johnnybegood
      - USER=clair
      - PORT=5432
      - INSTANCE=postgres
    ports:
      - "6060:6060"
      - "6061:6061"
    depends_on:
      - postgres
  postgres:
    build:
      context: ../blah/postgres
      dockerfile: Dockerfile
    ports:
      - "5432:5432"
    environment:
      - POSTGRES_PASSWORD=johnnybegood
      - POSTGRES_USER=clair
      - POSTGRES_DB=clair

Docker CMD is only designed to run a single process, following the docker philosophy of one process per container. Docker CMD仅设计为运行单个进程,遵循每个容器一个进程的docker理念。 Try using a start script to modify your template and then launch clair. 尝试使用启动脚本来修改模板,然后启动clair。

FROM quay.io/coreos/clair-git
COPY config.template /config/config.template
COPY start.sh /start.sh

#Set Defaults
ENV USER=clair PASSWORD=johnnybegood INSTANCE_NAME=postgres PORT=5432

RUN apk add gettext
ENTRYPOINT ["/start.sh"]

and have a startscript (with executable permissions) copied into the container using your Dockerfile 并使用Dockerfile将startscript(具有可执行权限)复制到容器中

!#/bin/sh

envsubst </config/config.template > /config/config.yaml
/clair -config=/config/config.yaml

edit: changed the answer after a comment from David maze 编辑:大卫迷宫的评论后更改答案

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM