[Bug] Agenta Variant container fails to start due to missing env var
Traceback (most recent call last):
File "/app/main.py", line 3, in <module>
import _app # This will register the routes with the FastAPI application
File "/app/_app.py", line 2, in <module>
from shared.constants import UserType
File "/app/shared/constants.py", line 39, in <module>
REDACTED_BUCKET= os.environ["REDACTED_BUCKET"]
File "/usr/local/lib/python3.10/os.py", line 680, in __getitem__
raise KeyError(key) from None
KeyError: 'REDACTED_BUCKET'
Expected behavior
It should use the environment variables I defined in .env. This environment variable is present there, it seems that the docker container never grabbed my environment variables when deploying this variant.
docker inspect (my variant container) outputs for "Env":
"Env": [
"PATH=/usr/local/bin:/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin",
"LANG=C.UTF-8",
"GPG_KEY=A035C8C19219BA821ECEA86B64E628F8D684696D",
"PYTHON_VERSION=3.10.14",
"PYTHON_PIP_VERSION=23.0.1",
"PYTHON_SETUPTOOLS_VERSION=65.5.1",
"PYTHON_GET_PIP_URL=https://github.com/pypa/get-pip/raw/dbf0c85f76fb6e1ab42aa672ffca6f0a675d9ee4/public/get-pip.py",
"PYTHON_GET_PIP_SHA256=dfe9fd5c28dc98b5ac17979a953ea550cec37ae1b47a5116007395bfacff2ab9"
],
To resolve the issue with the REDACTED_BUCKET environment variable not being loaded into your Docker container, follow these steps:
-
Include the
.envFile in Your Docker Image: Ensure yourDockerfilecopies the.envfile into the image. Use theCOPYcommand to place the.envfile in the same directory as your application code or wherever yourentrypoint.shscript expects it to be.
COPY path/to/your/.env /path/in/container/.env
-
Modify the
entrypoint.shScript: If your.envfile is located in a different spot within the container, update yourentrypoint.shscript to source the.envfile from its correct location.
#!/bin/bash
# Update the path to where your .env file is located
if [ -f /path/in/container/.env ]; then
source /path/in/container/.env
fi
exec python main.py
-
Rebuild and Run Your Docker Container: After making these adjustments, rebuild your Docker image and run your container. This ensures the
REDACTED_BUCKETenvironment variable is correctly loaded.
docker build -t your-image-name .
This approach ensures that your Docker container correctly sources the .env file, making the REDACTED_BUCKET environment variable available to your application.
Sources
About Dosu
This response is meant to be useful and save you time. It is not meant to be a precise solution, but rather a starting point for your own research.
Help me be more useful! Please leave a 👍 if this is helpful and 👎 if it is irrelevant.
If you want to continue the conversation, start your reply with @dosu-bot.