0

I am using Docker composé ver 1.5 or 6 and nginx image. I want to parameterize the nginx.config. To do that I want to create a var from $(basename some path). But the problem is Docker does not accept dynamic vars like that in env part of the Dockerfile. Another problem is that I also cannot map those variables on build run as Docker compose does not accept dynamic, scripted vars. How to overcome that issue?

From nginx
ENV myvar=$(basename /)

This is impossible to build the image.

The other way was

ARG myvar
ENV myvar2=myvar

But my version of Docker compose allows only to set

Environment: myvar=$(basename mypathinthevolume/)

That also does not seem to work

kol23
  • 1,498
  • 3
  • 16
  • 35
  • please, give us more information, paste your dockerfile and docker-compose at least – Sergio Tanaka Jul 14 '20 at 15:36
  • Have you looked at techniques like what's described in [Substitute environment variables in NGINX config from docker-compose](https://stackoverflow.com/questions/56649582/substitute-environment-variables-in-nginx-config-from-docker-compose)? If you create a template configuration and then rewrite it in your image's entrypoint, you can substitute content however you want. – David Maze Jul 14 '20 at 15:51
  • In the particular example of `$(basename /some/path)`, typically the filesystem layout of a Docker container is fixed and it's okay to hard-code paths there. If you're bind-mounting host content, require the container-side path to be _e.g._ `/data`. – David Maze Jul 14 '20 at 15:52
  • @David Maze that's the problem. I can't use static paths as the volume contents differ and I need the name in configuration. – kol23 Jul 14 '20 at 18:30
  • Another thing - I cannot use the nginx base image. I use FROM nginx so in effect I cannot map the variable in the same line/container as nginx is executed. – kol23 Jul 14 '20 at 18:36

0 Answers0