.env file and Docker Swarm

You may be disapointed as me to find out that .env file doesn’t work with Docker Swarm as it does with Docker Compose. This limitation can be frustrating, but there are some approaches. A quick fix lazy approach and a more secure one that includes Docker secrets. the quick fix lazy approach Navigate to your directory containing both .env and docker-compose.yml, then run: export $(cat .env) > /dev/null 2>&1; docker stack deploy <your_stack_name> --compose-file=docker-compose.yml This command reads your .env file and sets all secrets as env variables before deploying the stack. The security concern is really that the env variables become available to all processes launched from that shell session, not just Docker. Any script or command you run afterward could potentially read those env variables. ...

September 24, 2025

Prepare Docker compose config for Docker Swarm

Here’s a quick tip on how to convert docker-compose.yml file to a Docker Swarm mode ready file. the command Imma be straight to the point and share few commands to help you with converting a Docker Compose stack config to a Docker Swarm mode one: docker stack config --compose-file docker-compose.yml > swarm.yml To deploy it, run: docker stack deploy --compose-file swarm.yml my-service Notes: Replace my-service with your preferred stack name Use -c for shorthand for --compose-file why bother generating the file first You could skip this step and deploy directly (more on that below), but generating the resolved config first is worth it. The output shows you exactly what Docker Swarm will see after resolving all variable substitutions, extension fields, and merge keys. If something blows up during deployment, you’ll know whether it’s a config problem or a runtime problem. ...

September 24, 2025