3 ms·
I tried a setup with Nginx Unit and php-fpm inside a Docker container, but the way to load the config is so combersome I never was confident to use it in produc
by casperb 2y ago
I tried a setup with Nginx Unit and php-fpm inside a Docker container, but the way to load the config is so combersome I never was confident to use it in production. It feels like I am doing something wrong. Is there a way to just load a config file from the filesystem?
- jonatron 2y agohttps://unit.nginx.org/howto/docker/#apps-in-a-containerized-unit https://unit.nginx.org/howto/docker/#apps-in-a-containerized... > We’ve mapped the source config/ to /docker-entrypoint.d/ in the container; the official image uploads any .json files found there into Unit’s config section if the state is empty.
- casperb 2y agoI saw that, but I do like to make my own container. So I did roughly the same steps as they do. But it feels complicated.
- jonatron 2y agoCan you copy the official image's script? https://github.com/nginx/unit/blob/0e79d961bb1ea68674961da1703ffedb1ddf6e43/pkg/docker/docker-entrypoint.sh https://github.com/nginx/unit/blob/0e79d961bb1ea68674961da17...
- gawa 2y agoThe docs mentions: > The control API is the single source of truth about Unit’s configuration. There are no configuration files that can or should be manipulated; this is a deliberate design choice (https://unit.nginx.org/controlapi/#no-config-files https://unit.nginx.org/controlapi/#no-config-files) So yeah, the way to go is to run something like `curl -X PUT --data-binary @/config.json --unix-socket /var/run/control.unit.sock http://localhost/config/ http://localhost/config/` right after you start your nginx-unit. The way to manage a separate config step depends on how you manage to run the process nginx-unit (systemd, docker, podman, kubernetes...). Here's an example I found where the command is put in the entrypoint script of the container (see toward the end): https://blog.castopod.org/containerize-your-php-applications-using-nginx-unit/ https://blog.castopod.org/containerize-your-php-applications...
- casperb 2y agoI did that, but sometimes it takes a short moment before Unit is started, so you need a loop to check if Unit is responding before you can send the config. In total it was around 20 lines just to load the config. It feels like doing something wrong. Or using the wrong tool.
- ajayvk 2y agoI am building https://github.com/claceio/clace https://github.com/claceio/clace. It allows you to install multiple apps. Instead of messing with routing rules, each app gets a dedicated path (can be a domain). That way you cannot break one app while working on another. Clace manages the containers (using either Docker or Podman), with a blue-green (staged) deployment model. Within the container, you can use any language/framework.
- callahad 2y agoWe're very actively working on improving Unit's UX/DX along those lines. Our official Docker images will pick up and read configuration files from `/docker-entrypoint.d/`, so you can bind mount your config into your container and you should be off to the races. More details at https://unit.nginx.org/installation/#initial-configuration https://unit.nginx.org/installation/#initial-configuration But that's still kinda rough, so we're also overhauling our tooling, including a new (and very much still-in-development) `unitctl` CLI which you can find at https://github.com/nginx/unit/tree/master/tools/unitctl https://github.com/nginx/unit/tree/master/tools/unitctl. With unitctl today, you can manually run something like `unitctl --wait-timeout-seconds=3 --wait-max-tries=4 import /opt/unit/config` to achieve the same thing, but expect further refinements as we get closer to formally releasing it.
- casperb 2y agoThat sounds much better, thanks for the effort.