How to handle machine restarts with docker-compose

Hi,

I’m just trying to learn Doppler with my Raspberry PI 4. I have docker and docker-compose installed and I have a few different directories with different docker-compose.yml defined. I’ve just been using the following command to start my containerised services.

doppler run -- docker-compose up

It works well until I restart the PI and then all the containers restart as they are set to restart: unless-stopped but the problem is that they are now missing their secrets.

I feel like I’m missed something but I’m not sure on what that is.

Hi @dfgfefdc!

Welcome to the Doppler Community!

Yeah, unfortunately how you’re trying to use Doppler won’t work with the built-in Docker restart policies. If you would like that to work, you’d need to bake the Doppler CLI into your containers, pass in the DOPPLER_TOKEN, and execute the process inside the container using Doppler. That would get things working using that restart policy.

Aside from that, your best option is probably to move away from using docker-compose and swap to something like SystemD where you can specify the start/stop commands in the unitfile. Here’s a short article giving the basics around how you might do something like that:

I hope that helps! Let me know if you have any other questions!

Regards,
-Joel

Hi Joel,

Thanks for your reply. Systemd is a good idea. I’ll give it a try

Hi @watsonian,

I’ve just trying out the SystemD approach and I’m having issues with doppler not working. I’m not 100% on the issue with when I remove /usr/bin/doppler run command it seems to work just fine apart from missing the vars.

[Unit]
Description=Some des
PartOf=docker.service
After=docker.service

[Service]
Type=oneshot
RemainAfterExit=true
WorkingDirectory=somePath
ExecStart=/usr/bin/doppler run -- /usr/local/bin/docker-compose up -d --remove-orphans
ExecStop=/usr/bin/doppler run -- /usr/local/bin/docker-compose down

[Install]
WantedBy=multi-user.target

Any ideas?

Hi @dfgfefdc!

How is it failing? Do you have any logs from journalctl that you can share? I assume you’ve run doppler setup for the working directory you’re specifying since you aren’t passing in a DOPPLER_TOKEN environment variable – am I right? It’s probably not the cause of the trouble you’re seeing, but you likely don’t need to use doppler with the stop command, so that might simplify things a little bit as well.

Regards,
-Joel