Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Changing DOMAIN variable in .env file did not make traefik serve the app on that domain #1201

Answered by willhama
yohaoquan asked this question in Questions
Discussion options

First Check

  • I added a very descriptive title here.
  • I used the GitHub search to find a similar question and didn't find it.
  • I searched in the documentation/README.
  • I already searched in Google "How to do X" and didn't find any information.
  • I already read and followed all the tutorial in the docs/README and didn't find an answer.

Commit to Help

  • I commit to help with one of those options 👆

Example Code

# First part of the .env file at project root
# Domain
# This would be set to the production domain with an env var on deployment
# DOMAIN=localhost
DOMAIN=alang-my.tailscale.machine.ts.net
# Environment: local, staging, production
ENVIRONMENT=local
PROJECT_NAME="My Project Name"
STACK_NAME=my-stack-name
# Backend
# BACKEND_CORS_ORIGINS="http://localhost,http://localhost:5173,https://localhost,https://localhost:5173,http://localhost.tiangolo.com"
BACKEND_CORS_ORIGINS="http://my.tailscale.machine.ts.net,http://my.tailscale.machine.ts.net:5173,https://my.tailscale.machine.ts.net,https://my.tailscale.machine.ts.net:5173,http://my.tailscale.machine.ts.net"

Description

I followed the backend/development.md to change the domain. But even after doing

docker compose up -d

or

docker compose down
# Them manually deleting all related images, then
docker compose up -d

I can see that traefik is still trying to only serve on localhost. Accessing my custom domain returns a 404

image

Curiously, on the traefik dashboard, only the backend has the updated STACK_NAME applied to my backend, and all the rest still retained the project default stack name:

image

But no matter, as you can see, it is still trying to serve on localhost despite the fact that my env file changed to use a different domain.

Am I missing some configurations? Can someone help?
Thanks!

Operating System

Windows

Operating System Details

Docker version 26.0.0, build 2ae903e

Python Version

Python 3.12.2

Additional Context

No response

You must be logged in to vote

@yohaoquan I might have the answer for you. There seems some misconfiguration within the docker-compose.yml file. Currently it is defined as:

 env_file:
 - .env
 environment:
 - DOMAIN=${DOMAIN}

By priority it takes DOMAIN from your host env variables first and overwrites the one in the .env when you run docker compose up.

Try to execute echo $DOMAIN on your host environment and see whats coming there.

Actually, I am not sure why both are defined in the docker-compose.yml file.

You can remove the following line and it should work fine:

- DOMAIN=${DOMAIN}

@tiangolo why do you declare the environment and the .env file in docker-compose.yml?

Replies: 1 comment 4 replies

Comment options

@yohaoquan I might have the answer for you. There seems some misconfiguration within the docker-compose.yml file. Currently it is defined as:

 env_file:
 - .env
 environment:
 - DOMAIN=${DOMAIN}

By priority it takes DOMAIN from your host env variables first and overwrites the one in the .env when you run docker compose up.

Try to execute echo $DOMAIN on your host environment and see whats coming there.

Actually, I am not sure why both are defined in the docker-compose.yml file.

You can remove the following line and it should work fine:

- DOMAIN=${DOMAIN}

@tiangolo why do you declare the environment and the .env file in docker-compose.yml?

You must be logged in to vote
4 replies
Comment options

Hey @willhama I appreciate you answer, there are lots of .env declarations in the docker-compose.yml should we remove all of them?

Comment options

Hey @niyazikemer I personally prefer to have the env variables all in the .env file. DevOps can be tedious and a concisely written .env file is much easier to manage. In your docker-compose.yml you define both. So I would suggest removing all env variables from the environment section in the docker-compose.yml file unless its a variable that is actively passed to the shell (e.g. timestamps or build-stamps) or you need them during your CICD steps.

Comment options

Ahh sorry for the misunderstanding. I was not the owner of the original question. Basically I am having a similar problem. I've deployed my app without any error it looks it is working. But the site seems dead from the outside world. I believe there is a problem with the traefik. I'll try then maybe I can create a discussion for my specific case. Thanks for your help.

Comment options

@niyazikemer be sure you open your ports to the outside on the server. 443 and 80. As well define the env variables correctly so the SSL certificate can be loaded correctly.

Answer selected by yohaoquan
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
question Further information is requested

AltStyle によって変換されたページ (->オリジナル) /