Passing Environment Variables in a File


Recommended Posts

I am using Homepage docker container and have it all setup but do not want to expose API credentials clear text - I have created an env file to load these at docker runtime using –env-file .env - is it possible to use this in the docker setup in Unraid as although I can set variable I have 30 or so to maintain. I refererence for the setup I am testing.

 

 

Thanks in Advance for any help :)

Edited by msryhajw
Link to comment
  • 1 month later...

Got it working just now, also setting up homepage.

 

First, you will need to create that .env file.

 

In the docker tab, click on "Homepage" then edit. Toggle the "basic view" switch to go into "Advanced view".

 

In "Extra parameters", add this (change the actual path to your .env file)

--env-file /mnt/cache/appdata/homepage/.env

 

Click "Done" and it should now destroy the old container and recreate it. You should see the extra param (last line) added to the docker run, like so

docker run
  -d
  --name='homepage'
  -l net.unraid.docker.managed=dockerman
  -l net.unraid.docker.webui='http://[IP]:[PORT:3000]'
  -l net.unraid.docker.icon='https://raw.githubusercontent.com/gethomepage/homepage/main/public/android-chrome-512x512.png'
  -v '/mnt/cache/appdata/homepage/config/':'/app/config':'rw'
  -v '/var/run/docker.sock':'/var/run/docker.sock':'ro'
  -v '/mnt/user/appdata/homepage/icons/':'/app/public/icons':'rw'
  --env-file /mnt/cache/appdata/homepage/.env 'ghcr.io/gethomepage/homepage:latest'

 

Please be aware that if you make any changes to the env file once the container has been loaded, you will need to re-create it. Stopping & starting or restarting the container will not change the env file.

 

The easiest way I found to force UnRAID to recreate the container with the new contents of the env file was to go into edit, change the "console shell command" from whatever it is set to the other and then hitting "Done". Once you're happy with your env file, revert back the console shell command to "shell"

 

Happy setup 😄

  • Like 1
Link to comment
  • 4 weeks later...
On 3/29/2024 at 9:22 AM, SlavSquat said:

Got it working just now, also setting up homepage.

 

First, you will need to create that .env file.

 

In the docker tab, click on "Homepage" then edit. Toggle the "basic view" switch to go into "Advanced view".

 

In "Extra parameters", add this (change the actual path to your .env file)

--env-file /mnt/cache/appdata/homepage/.env

 

Click "Done" and it should now destroy the old container and recreate it. You should see the extra param (last line) added to the docker run, like so

docker run
  -d
  --name='homepage'
  -l net.unraid.docker.managed=dockerman
  -l net.unraid.docker.webui='http://[IP]:[PORT:3000]'
  -l net.unraid.docker.icon='https://raw.githubusercontent.com/gethomepage/homepage/main/public/android-chrome-512x512.png'
  -v '/mnt/cache/appdata/homepage/config/':'/app/config':'rw'
  -v '/var/run/docker.sock':'/var/run/docker.sock':'ro'
  -v '/mnt/user/appdata/homepage/icons/':'/app/public/icons':'rw'
  --env-file /mnt/cache/appdata/homepage/.env 'ghcr.io/gethomepage/homepage:latest'

 

Please be aware that if you make any changes to the env file once the container has been loaded, you will need to re-create it. Stopping & starting or restarting the container will not change the env file.

 

The easiest way I found to force UnRAID to recreate the container with the new contents of the env file was to go into edit, change the "console shell command" from whatever it is set to the other and then hitting "Done". Once you're happy with your env file, revert back the console shell command to "shell"

 

Happy setup 😄

 

 

Just wanted to say thanks for sharing this.  I'd been scratching my head for a while, thinking I might have to move the config to another server that can run docker compose configurations.

Link to comment

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.
Note: Your post will require moderator approval before it will be visible.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.