0

I've been trying to set up a Docker environment, where the frontend (Angular/TypeScript in our case) is built in the Docker file and then served through Nginx.

We want to keep the Docker images environment-agnostic (so we can change our environment without having to rebuild the images). This means we can't build the code with environment variables. So far the options we see are:

  • inject the values on serving the code (probably some performance impact, don't know any neat way of doing this)
  • still build separate images (& drop our requirement)
  • have all environments compiled into the code with environment.<env>.ts files (not really agnostic images, just between a static set of environments)

Is there any recommended method of doing this? Am I missing something? I feel like this should be a solved problem, but I can't find anything on how to do this "properly".

Martijn Arts
  • 723
  • 7
  • 22
  • try to relogin to this registry – Meiram Chuzhenbayev Jul 09 '18 at 10:21
  • @MeiramChuzhenbayev I'm not sure I understand what you mean. What registry? – Martijn Arts Jul 09 '18 at 10:35
  • what do you mean by agnostic way? – Dmitrii G. Jul 09 '18 at 10:50
  • You need to inject the values somewhere. What would your ideal point be? – Aankhen Jul 09 '18 at 11:10
  • @DmitriiG. I've edited the post, hopefully that clarifies a little bit what I'm looking for. We want to be able to change the environment without having to change the code. – Martijn Arts Jul 09 '18 at 14:08
  • @Aankhen this is my question: the "ideal" method is to have the environment be read during runtime, but since we're serving static files to only way to do that is to inject them in _during_ serving, which doesn't seem like a very robust solution. – Martijn Arts Jul 09 '18 at 14:08
  • I’m confused because it sounds like you have a solution but you (rightly) don’t want to use it since it isn’t a good idea. What’s the reason for wanting to delay the environment configuration until runtime, and what exactly constitutes the environment, in your eyes? It may be that we’re talking about different things. – Aankhen Jul 09 '18 at 17:54
  • @Aankhen the environment (for example, the domain name, the url for the backend APIs; stored in environment variables) would have to be somehow injected into the code, after starting the Docker container. The code has to be served _with_ embedded environment values. Injecting _after_ start means either we have some script run after starting the container that replaces all occurrences of `ENVIRONMENT_VAR` with the value of that variable, or we do it through nginx (replacing them before sending the files to the client). – Martijn Arts Jul 10 '18 at 12:51
  • Okay. Maybe this will help: https://stackoverflow.com/questions/30494050/how-do-i-pass-environment-variables-to-docker-containers – Aankhen Jul 10 '18 at 14:06
  • Are you trying to do this https://github.com/moby/moby/issues/8838 ? – Dmitrii G. Jul 10 '18 at 15:12
  • 1
    A potential answer is provided [here](https://stackoverflow.com/a/53656839/2249614). They inject the env-specific values during container start, so no performance impact once the container is running. – Fabian Braun Dec 07 '18 at 15:05

0 Answers0