mls_dev
mls_dev

Reputation: 531

docker swarm: use secrets for enviroments variable

I am using docker swarm with portainer for deploy apps that before was directly in proxmox vms.

I want improve the deploy flow with cluster swarm and the configuration with secrets.

I define with portainer the secrets in the swarm cluster

I am starting with wordpress, but the secrets don't work like i expect. I want use the secrets for complete the enviroments variables, but this keep empty:

version: "3.8"
secrets:
  mysql_ip_proxmox_lan_real:
    external: true
  mysql_password_user_wordpress:
    external: true
  mysql_password_proxmox_wordpress:
    external: true
services: 
  wordpress:
    restart: always
    image: wordpress:latest
    ports:
       - "8080:80"
    environment:
       WORDPRESS_DB_HOST: ${mysql_ip_proxmox_lan_real}:3306
       WORDPRESS_DB_USER: ${mysql_password_user_wordpress}
       WORDPRESS_DB_PASSWORD: ${mysql_password_proxmox_wordpress}
       WORDPRESS_DB_NAME: wordpress
    secrets:
      - mysql_ip_proxmox_lan_real
      - mysql_password_user_wordpress
      - mysql_password_proxmox_wordpress

what is the proper way to do this?

Upvotes: 0

Views: 872

Answers (2)

Based on the documentation from: https://hub.docker.com/_/wordpress, you can append a _FILE to any of the environment variable and reference the /run/secrets/<secret_filname>

Upvotes: 1

Drake
Drake

Reputation: 443

Have you tried referencing the secrets like so?:

WORDPRESS_DB_USER:/run/secrets/mysql_password_user_wordpress

As best I can tell (I'm no expert), everything else is correct. I'm not sure if appending the port would work or not though. If the above works, and you still have issues with the port, maybe just add that to the secret?

Upvotes: 0

Related Questions