0

While setting up and configure some docker containers I asked myself how I could automatically edit some config files inside the container after the containerized service finished installing (since the config files are created at the installation).

I have tried that using a shell file and adding it as the entrypoint in the Dockerfile. However, as I have said the config file does not exist right at the beginning and hence the sed commands in the script fail.

Linking an config files with - ./myConfig.conf:/xy/myConfig.conf is also not an option because the config contains some installation dependent options.

The most reasonable solution I have found was running a script, which edits the config, manually after the installation has finished with docker exec -i mycontainer sh < editconfig.sh

EDIT

My question is formulated in general terms. However, the question arose while working with Nextcloud in a docker-compose setup similar to the official example. That container contains a config.php file which is the general config file of Nextcloud and is generated during the installation. Certain properties of that files have to be changed (there are only a very limited number of environmental variables to specify). Since I am conducting some tests with this container I have to repeatedly reinstall it and thus reedit the config file.

jeanggi90
  • 741
  • 9
  • 24
  • Can you share a little more of your setup, maybe the `Dockerfile`? Usually you'd install software in the `Dockerfile`, and the ENTRYPOINT script would run later; similarly, there wouldn't be any variation in installation options between different containers on the same image. – David Maze Mar 03 '19 at 11:11
  • @DavidMaze thanks, I have edit my question and described my specific problem. – jeanggi90 Mar 03 '19 at 11:57
  • I do not exactly understand your needs. You run single container in cloud service (ECS for example) or you have your own VMs. If you explain wider your needs I'll be surer to suggest a solution... – ozlevka Mar 03 '19 at 13:53
  • @ozlevka I am sorry for not expressing myself clearly enough. I have locally a dedicated server running Linux and docker on it. I am running multiple docker services in dedicated containers like webserver, revereproxy etc. This way I am also running the Nextcloud container, which is dependent on a db and a webserver. They are combined with a `docker-compose` file. When I reinstall these services I have to manually edit the `config.php` file which lies inside the Nextcloud container. I am looking for a way to make these changes automatically after the service was installed successfully. – jeanggi90 Mar 03 '19 at 17:04
  • aren't the environment variables described at https://hub.docker.com/_/nextcloud sufficient? What additional settings aren't handled by those? – Thomasleveil Mar 03 '19 at 18:23

2 Answers2

1

Maybe you can try another approach and have your config file/application pick its settings from the environmental variables. That would be consistent with the 12factor app methodology see here

jkrol2
  • 394
  • 1
  • 6
0

How I understand your case you need to start your container from creating config by some template.

I see a number of options to do it:

  1. Use some script that generates a config from template and arguments from a command line or environment variables. (Jinja2 and python for example or Mustache and node.js ). In this case, your entrypoint generate the template and after this start application. For change config, you will be forced restart service (container).

  2. Run some service can save the configuration and render you configuration in run time. Personally, I like consul template, we active use this engine in our environment, and have no problems for while. In this case, config is more dynamic and able to be changed "on the fly". In your container, you will have two processes, application, and consul-template daemon. Obviously, you will need to run and maintain consul. For reloading config restart of an application process is enough.

  3. Run a custom script to create the config. :)

ozlevka
  • 1,988
  • 16
  • 28