0

I was looking at this answer https://stackoverflow.com/a/37904830/169252 to try to solve my problem.

However, it doesn't seem to work for my case

ENV API="list,create,delete"
ENV ID="1-1"
ENV VERBO=5

ENTRYPOINT /myapp --id=$ID --api=$API --origin="*" --trace --metrics --verbosity=$VERBO  --allow-insecure

However, I always get invalid value "" for flag -verbosity: if not provided by the docker run command, i.e.

docker run -p 80:8080 $DOCKER_IMAGE.

However, if I run it as

docker run -p 80:8080 -e VERBO=4 $DOCKER_IMAGE, it seems to work (have another issue right now after this so can't post actual result).

Am I using this correctly? The idea is that VERBO is an optional argument and doesn't need to be set by docker run -only if so desired.

This is the complete Dockerfile:

  FROM golang:1.19-alpine as builder    
               
  RUN apk add --no-cache make gcc musl-dev linux-headers git    
      
  WORKDIR /go/myapp    
  COPY . .    
      
  ARG GOPROXY    
  RUN go mod download    
  RUN make myapp    
              
              
  ENV API="list,create,delete"    
  ENV ID="1-1"    
  ENV VERBO=5             
      
  FROM alpine:latest    
      
  RUN apk add --no-cache ca-certificates    
      
  COPY --from=builder /go/myapp/build/myapp /    
                 
  ENTRYPOINT /myapp --id=$ID --api=$API --origin="*" --trace --metrics --verbosity=$VERBO  --allow-insecure
transient_loop
  • 5,984
  • 15
  • 58
  • 117

1 Answers1

1

The declaration of ENV VERBO=5 is correct and sets the default to 5.

To troubleshoot the problem, run the container and inspect it:

docker run -p 80:8080 $DOCKER_IMAGE
docker ps -a
docker container inspect <container-id>

Within the Config dictionary, check the value of Env list that should contan also VERBO=5.

 "Env": [
     "PATH=...",
     "VERBO=5"
 ]

If there is that key-value means you've set the default value correctly.

Checking your Dockerfile, your issue is related to the multiple declaration of the base image (FROM command) that creates multiple contexts in your container. So, the VERBO value is not global and you need to set the default value also in the second part:

...
FROM alpine:latest
ENV VERBO=5
...
Alez
  • 1,913
  • 3
  • 18
  • 22
  • What I am saying is that if I start it like that: `docker run -p 80:8080 $DOCKER_IMAGE`, then my container doesn't even boot, with the "invalid value" error I described in the question. Only if I explicitly provide the env var with -e it seems to pick it: `docker run ... -e VERBO=4 $DOCKER_IMAGE` – transient_loop Jun 19 '23 at 15:55
  • Could you please share the Dockerfile you're using? – Alez Jun 19 '23 at 22:49
  • I added the complete file to the question. – transient_loop Jun 26 '23 at 16:16
  • I edited my answer with the line to add in order to solve your issue. – Alez Jun 28 '23 at 12:22