How do I correctly set environment variables for an existing vaultwarden docker container?

I am on Ubuntu server 20.0.4 and have installed Vaultwarden using docker as described in the wiki. I also have a Let’s Encrypt certificate and run Vaultwarden behind an Apache reverse proxy and basically it is working fine already.

However, what I did not manage is to set some essential environment variables. Consequently, I could not make Vaultwarden save its log files outside of the container - which however seems to be a requirement for properly setting up fail2ban.

For instance I tried to make Vaultwarden save it’s logs to a log file in my host directory /usr/vw-data with this (as recommended here):
docker run -d --name vaultwarden -e LOG_FILE=/data/vaultwarden.log
But I only get:
"docker run" requires at least 1 argument.

The same happens with all the other commands to set env vars which are listed in the wiki! What am I doing wrong here?

I am not exactly an expert in docker and unfortunately most of the tutorials I have found are pretty basic and only cover what I have already achieved - and learning docker from scratch is a bit above my head :wink:

Please note: I currently do not use portainer or docker-compose - just docker 20.10.8

I would really appreciate if someone could help me here!
Cheers, David

I think you are missing one last argument.
docker run -d --name vaultwarden -e LOG_FILE=/data/vaultwarden.log
docker run -d --name vaultwarden -e LOG_FILE=/data/vaultwarden.log vaultwarden/server:latest
However, you need a port too.

I know this doesn’t exactly answer your problem, but I highly recommend using docker-compose – it will take about 30 minutes to 1 hour to learn, but once you learn how to use this tool, it’s really very easy and you have much better control of your arguments you pass to docker.

1 Like

Thanks for your answers! What I first didn’t realize, is that it seems to be necessary to set the env vars upon the initial creation of the container. Because doing so, when the container is already up and running apparently will not work as you’ll always get a message from docker that a container with that name already exists…
Anyway, what I ended up doing was to stop the container
docker stop vaultwarden,
then delete it
docker rm vaultwarden
and then re-create it with the following command:
docker run -d --name vaultwarden -e ADMIN_TOKEN=my_random_token -v /usr/vw-data/:/data/ -p 8080:80 vaultwarden/server:latest

This way I could access the admin interface right from the beginning and could continue everything from there. The documentation in the wiki isn’t exactly helpful in that respect as the commands shown there, will not work for anyone having already a running vaultwarden container. Or maybe I understand something wrong here, but at least the didn’t work in my case.

thanks for the awesome information.

thanks my issue has been fixed.