2

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
Benji
  • 41
  • 2

1 Answers1

0

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

anderio Moga
  • 425
  • 7
  • 11
  • 1
    It's actually important in this setup that `envsubst` not get run until container startup time. Presumably `config.template` contains references like `$USER` and `$PASSWORD`, and this replaces them with the values specified in the `docker-compose.yml` file. (I'd probably use an entrypoint script rather than the long `CMD`.) – David Maze Sep 16 '19 at 10:26
  • @DavidMaze I didn't realise what envsubst did. I have changed my answer accordingly, but I don't know if a startup script is the best solution. – anderio Moga Sep 16 '19 at 14:04
  • this causes `standard_init_linux.go:211: exec user process caused "no such file or directory` – Benji Sep 16 '19 at 23:03
  • After some searching, I discovered that Alpine does not ship with bash, but with sh. I will change my answer, that will probably solve the problem – anderio Moga Sep 17 '19 at 07:48
  • unfortunately, I get the same error as I did originally; `/start.sh: line 3: can't open /config/config.template: no such file` – Benji Sep 18 '19 at 00:02
  • config.template is owned by root, maybe its permissions related, I would expect another error if that was the case however. – anderio Moga Sep 18 '19 at 07:06