Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

.env file is unable to use environment variables declared within itself #95

Open
Southpaw1496 opened this issue Apr 30, 2022 · 7 comments

Comments

@Southpaw1496
Copy link

I recently started using Mattermost with Docker. As instructed in the Deployment Guide, I cloned the repository, copied the env.example file to a .env file, filled out the environment variables and started the server. However, it didn't start properly and after viewing the logs with docker logs, the error turned out to be

Error: failed to load configuration: failed to create store: unable to load on store creation: invalid config: Config.IsValid: model.config.is_valid.site_url.app_error, 
Usage:
  mattermost [flags]
  mattermost [command]

After some thought, I noticed that MM_SETTINGS_SITEURL (line 38) was using https://${DOMAIN} as its value, so I hardcoded my domain into it instead of using the environment variable. After that, I received this error:

{"timestamp":"2022-04-24 15:34:38.346 Z","level":"error","msg":"Failed to ping DB","caller":"sqlstore/store.go:272","error":"parse \"postgres://${POSTGRES_USER}:${POSTGRES_PASSWORD}@postgres:5432/${POSTGRES_DB}?sslmode=disable&connect_timeout=10\": net/url: invalid userinfo","retrying in seconds":10}

This error clearly shows that the file is interpreting the environment variables literally instead of as environment variables, so I hardcoded the credentials into MM_SQLSETTINGS_DATASOURCE and Mattermost was able to successfully connect to the database and launch. There are also two other variables which use other variables, namely CERT_PATH (line 41) and KEY_PATH (line 42), but since I don't use Gitlab SSO, I haven't tried them.

I'm using Docker 20.10.14 on Debian GNU/Linux 11 (bullseye).

@florius0
Copy link

florius0 commented May 5, 2022

I've faced same issue and can confirm that POSTGRES_USER, POSTGRES_PASSWORD and POSTGRES_DB are ignored and MM_SQLSETTINGS_DATASOURCE is postgres://:@postgres:5432/?sslmode=disable&connect_timeout=10 inside mattermost container

@florius0
Copy link

florius0 commented May 5, 2022

Caused by docker/compose#9442

@florius0
Copy link

florius0 commented May 6, 2022

As a workaround one may use the following script

IFS=$'\n'
for e in `grep -v '^#' .env`; do export `echo $e | envsubst`; done

docker compose -f docker-compose.yml -f docker-compose.nginx.yml build
docker compose -f docker-compose.yml -f docker-compose.nginx.yml down
docker compose -f docker-compose.yml -f docker-compose.nginx.yml up -d

It reads and interpolates .env file into environment variables.

@hubortje
Copy link

hubortje commented Sep 15, 2022

I'm having trouble with the following error-messages:

WARN[0000] The "POSTGRES_IMAGE_TAG" variable is not set. Defaulting to a blank string.
WARN[0000] The "RESTART_POLICY" variable is not set. Defaulting to a blank string.
WARN[0000] The "POSTGRES_DATA_PATH" variable is not set. Defaulting to a blank string.
WARN[0000] The "RESTART_POLICY" variable is not set. Defaulting to a blank string.
WARN[0000] The "MATTERMOST_CONFIG_PATH" variable is not set. Defaulting to a blank string.
WARN[0000] The "MATTERMOST_DATA_PATH" variable is not set. Defaulting to a blank string.
WARN[0000] The "MATTERMOST_LOGS_PATH" variable is not set. Defaulting to a blank string.
WARN[0000] The "MATTERMOST_PLUGINS_PATH" variable is not set. Defaulting to a blank string.
WARN[0000] The "MATTERMOST_CLIENT_PLUGINS_PATH" variable is not set. Defaulting to a blank string.
WARN[0000] The "MATTERMOST_BLEVE_INDEXES_PATH" variable is not set. Defaulting to a blank string.
WARN[0000] The "MATTERMOST_CONTAINER_READONLY" variable is not set. Defaulting to a blank string.
error while interpolating services.mattermost.read_only: failed to cast to expected type: invalid boolean:

Is this related to this issue?

@anx-ag
Copy link

anx-ag commented Oct 20, 2022

Your docker-compose version is too old, please see this thread for details. You will need to have at least 1.26.0, which is the first version that supports variable substitution in your .env files.

@Zenitugo
Copy link

Zenitugo commented Jul 9, 2024

WARN[0000] The "DOMAIN" variable is not set. Defaulting to a blank string.
WARN[0000] The "DOMAIN" variable is not set. Defaulting to a blank string.
WARN[0000] The "ACME_EMAIL" variable is not set. Defaulting to a blank string.
WARN[0000] The "DOMAIN" variable is not set. Defaulting to a blank string.
WARN[0000] The "DOMAIN" variable is not set. Defaulting to a blank string.
WARN[0000] The "DOMAIN" variable is not set. Defaulting to a blank string.
WARN[0000] The "DOMAIN" variable is not set. Defaulting to a blank string.
WARN[0000] The "POSTGRES_USER" variable is not set. Defaulting to a blank string.
WARN[0000] The "POSTGRES_PASSWORD" variable is not set. Defaulting to a blank string.
WARN[0000] The "POSTGRES_DB" variable is not set. Defaulting to a blank string.
WARN[0000] The "DOMAIN" variable is not set. Defaulting to a blank string.
WARN[0000] The "DOMAIN" variable is not set. Defaulting to a blank string.
WARN[0000] The "DOMAIN" variable is not set. Defaulting to a blank string.
WARN[0000] The "DOMAIN" variable is not set. Defaulting to a blank string.

I'm also encountering the same error. I have installed the newest version of docker-compose and the error still remains

@EntityinArray
Copy link

EntityinArray commented Aug 29, 2024

https://docs.mattermost.com/install/install-docker.html
Failing at step 6.

root@emity-gaming:~/docker-composes/mattermost/docker# docker compose -f docker-compose.yml -f docker-compose.without-nginx.yml up -d
WARN[0000] The "POSTGRES_DATA_PATH" variable is not set. Defaulting to a blank string.
WARN[0000] The "POSTGRES_IMAGE_TAG" variable is not set. Defaulting to a blank string.
WARN[0000] The "RESTART_POLICY" variable is not set. Defaulting to a blank string.
WARN[0000] The "MATTERMOST_IMAGE" variable is not set. Defaulting to a blank string.
WARN[0000] The "MATTERMOST_IMAGE_TAG" variable is not set. Defaulting to a blank string.
WARN[0000] The "MATTERMOST_CONTAINER_READONLY" variable is not set. Defaulting to a blank string.
error while interpolating services.mattermost.read_only: failed to cast to expected type: invalid boolean:

I'm not using docker-compse, because it was obsoleted.
I'm using docker 27.0.3

I'm sorry, i made a typo in step 2:

#I did
cp env.example env
#When I should have done
cp env.example .env

Now it works

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

6 participants