Vars and docker-compose and dockerfile

have a docker configuraition with

  • one dockercompose file
  • for some service and dockerfile with extras

What i like to achive is that a i can ull latest images form dockerhub or (When they are not ok), use ny own save dockerhub images on localhost:5000

I like to use a .env var for this where a variable (TAG) is empty or filled with a prefix for the image so that the local image is pulled
I have a sort of way of doing this , and like to check if this is gonna work!
I only described the parts that are relevant for this purpose

Can somebody, a pro check this for me, i am an amateur :slight_smile:

env file (dynamic written by script)

TAG=localhost:5000/ (or TAG is empty and then the dockerhub store is used and the default name of the image)

dockercompose

service_a (dockerfile is used, see dockerfile env/arg)
build: /home/pi/pvkmenu/services/homer/.

service_b
image: “${TAG}b4bz/homer:latest”

dockerfile for service a

ARG TAG
ENV envTAG=$TAG
FROM ${envTAG}b4bz/homer:latest

CMD
docker-compose up (same folder as .env)

(als .env op n andere plaats staat / andere naam)
docker-compose --env-file ./config/.env.dev config

Didn’t you test it before posting?

The variable you call TAG actualy is the optional registry part of a repo and not a tag.
I am not sure if the declaration of the base image works as you designed it. This works:

ARG REGISTRY
FROM ${REGISTRY}b4bz/homer:latest
...

I have no idea about the .env part. I always used my own templating to generate compose files on the fly.

Pitty, you didn’t include the output of this command, is it would have allowed to see if the interpolation works as you watned.

I will try the setup this weekend and inform you…

It did work, by

  • using env vars for selecting registry/images in docker-compose

  • and for registry/images in dockerfiles by using
    build:
    context: /home/pi/pvkmenu/services/motioneye/.
    args:
    MYHUB: “${EMYHUB}ccrisan/motioneye:master-armhf”
    in the compose file and

  • and using ARG in the dockerfile

now i can programm which registry/library to use!