S
S
Shura Gear2020-04-24 16:35:16
Angular
Shura Gear, 2020-04-24 16:35:16

How to edit a file in a docker image before executing it?

Good day.
Task: edit the configuration file (replace with sed) before starting the container.
The bottom line: there is a docker image, which is an assembled angular application with a specific base-href. Image is universal and rolls out in a compartment with others using docker-compose, combining several UIs and a bunch of microservices for backing. Since the rollout takes place at different sites, it became necessary to roll it out with a different base-href from the options to simply rebuild the container for the site, but since this is not according to the canon, we decided to change the base-href in index.html before launching. That’s all, but I didn’t find anything except command for these purposes and the code began to look terrible

ui-app1:
    image: harbor.example.local/project/gui/ui-app1:1.0.3
    ports:
      - "8981:80"
    network_mode: "bridge"
    command: >
      sh -c "sed -i -E 's|/test/|/public/test/|' /usr/share/nginx/html/ui-app1/index.html &&
      nginx -g 'daemon off;'"
    volumes:
      - type: bind
        source: ./ui-app1/default-area1.conf
        target: /etc/nginx/conf.d/default.conf
    depends_on:
      - haproxy


Hence the question, is there another, more beautiful solution?
While I was writing, the idea of ​​building a new image based on the current one came to mind (I just copy the contents of /usr/share/nginx/html/ and then edit index.html... but also the same %)

Answer the question

In order to leave comments, you need to log in

1 answer(s)
D
de1m, 2020-04-25
@de1m

Well, it's really terrible, it's terrible when there are five lines of commands in the command.
In general, if the image is yours, then make a variable to make changes in it. If the image is not yours, then only with commands, you can still mount the script and execute it with the command.

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question