简体   繁体   中英

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

My Dockerfile is as follows:

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 :

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. 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

My docker-compose.yml file:

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. Try using a start script to modify your template and then launch 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

!#/bin/sh

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

edit: changed the answer after a comment from David maze

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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