In my flask app I have
# python
password = os.environ.get('PASSWORD_MONGODB') or os.getenv("PASSWORD_MONGODB")
username = os.environ.get('USERNAME_MONGODB') or os.getenv("USERNAME_MONGODB")
And I need to use dockerfile, to build image. But it needs those two variables.
I should use secrets, but I’m confused by docs, what I should type, and how to simply use it as variables in code as well.
I’ve tried:
docker build backend/ --file backend/Dockerfile --tag my_backend_image:latest --secret id=USERNAME_MONGODB USERNAME_MONGODB="" --secret id=USERNAME_MONGODB USERNAME_MONGODB="usr"
but gives:
unknown flag: --secret
And for normal variables only this works:
ENV USERNAME_MONGODB "pass"
but i can’t put those in dockerfile, it needs to be passed as args, which doesn’t work (normal variables either):
Dockerfile:
ARG USERNAME_MONGODB
ARG PASSWORD_MONGODB
ENV MONGODB_USERNAME=${USERNAME_MONGODB}
ENV MONGODB_PASSWORD=${PASSWORD_MONGODB}
command:
docker run -d \
-p 8080:5000 \
--build-arg MONGODB_USERNAME=usr \
--build-arg MONGODB_PASSWORD=pass \
--name animanga_backend \
animanga_backend:2.0
I get “None” for both variables, so not passed.
This works, but I use Render platform, so they just execute docker image
docker run -d -p 8080:5000 -e USERNAME_MONGODB='user' -e PASSWORD_MONGODB='pass' --name animanga_backend animanga_backend:2.0