How to set environement variables?

Hello all! :smiley:

Let me start off with that I’ve read all of the documentation over at the wiki on the Github repo. I just don’t get the documentation, as a newbie to docker the documentation lacks some more step-by step.

I would like to run BitwardenRS behind Nginx, but before I do that I would like to have it up and running with just docker first.

I have a working BitwardenRS docker running that is accessible however I just can’t manage to find out how to set environment variables. Am I supposed to enter the Docker container and modify an environment file (which I can’t seem to find), if so: What’s the preferred / recommended way to enter the docker container?

When I take a look at the configuration section of the wiki every configuration says you need to do the following to set the variable (we’ll take the SIGNUPS_ALLOWED variable as an example):

docker run -d --name bitwarden \
  -e SIGNUPS_ALLOWED=false \
  -v /bw-data/:/data/ \
  -p 80:80 \
  bitwardenrs/server:latest

The only way I manage to apply this is by stopping the docker containers, then removing it docker rm bitwarden and then apply the above. This can’t possibly be how I’m supposed to set these variables, is it?

So my question boils down to: How do I set environment variables?

Thanks in advance for your answers!

Hugo

Aside from -e when using the command line, there are two other ways to specify environment variables when using docker.

The optimal way is by using a .env file. (That link points to a default .env template example - save it to your working directory, change it to your needs, and name it .env or bitwarden_rs.env or something.)

The other way is to set them inside a docker-compose.yml file used to startup bitwarden_rs and nginx. Just specify your environment variables under the environment: section, as shown in the wiki example.

If you use a systemd entry, you can set EnvironmentFile=/path/to/anyfilename.env to point to your .env file.

Either way, for the .env file, docker-compose should automatically load any .env file that resides in the same directory as your docker-compose.yml.

1 Like

Thanks! This may sound dumb: But what’s the working directory in this instance?

Additionally: How can I complete remove all data associated to Bitwardenrs? I want to do a fresh install but removing the docker container and volume using docker rm -v bitwarden isn’t removing the data because once I do docker run again I can still log-in with a previously created account and all the settings are saved.

I got into the working directory using docker exec -it bitwarden bash which I had already previously done but I now realize this is the working directory. My last question still remains: How can I remove all data associated with bitwarden so I can make a clean start?

Edit: When I’m in the working directory using docker exec -it bitwarden bash I can’t use nano / vim. How am I supposed to create the .env file?

The working directory is the directory on your server you ran the docker (or docker-compose) command in to start bitwarden_rs. It is not inside the docker container.

As for completely removing all data associated with bitwarden_rs, the directory containing all the data is most likely in your working directory too. You just need to delete the data directory that was created on your server (again, not inside the container). As an example, if you followed the wiki and used ‘-v /bw-data/:/data/’ then your data directory would be called ‘bw-data’ and it will contain db.sqlite3, a few folders, and possibly a few extra files. Stop the container, rm the bw-data directory, then when you start it again it will be like starting over from scratch (* be warned, everything will be deleted - the database, any attachments, any ssl certs you placed there, etc).

1 Like

For some reason the .env isn’t being applied. To be clear I’ve set variables that aren’t defined by the config.yml like WEBSOCKET_ADDRESS=0.0.0.0 and WEBSOCKET_PORT=3012 using nano .env and thereafter doing docker stop bitwarden && docker rm bitwarden and then docker run -d --name bitwarden -v /bw-data/:/data/ -p 80:80 bitwardenrs/server:latest

Could you confirm this is the correct way to do this?

My bad, sorry about that.

The .env file is only auto-loaded when using docker-compose.

When using docker run you need to add the command-line argument: —env-file /path/to/.env

1 Like