How to pass service variables to docker container (runtime only)
ethanlaj
HOBBYOP

a year ago

I am aware that if we want to pass a service variable to a container during the build stages, we have to use ARG, but in my case the running app only needs it. How would I do this?

Solved

54 Replies

ethanlaj
HOBBYOP

a year ago

9d88d41d-d840-4ff7-9796-a4dcf88468f1


a year ago

for a Dockerfile build, just dont use ARG in your Dockerfile and the variables will not be available during build!


ethanlaj
HOBBYOP

a year ago

Yeah, but will they be available during runtime? I'm running into that issue


a year ago

yes they will


ethanlaj
HOBBYOP

a year ago

HMM

1323700056347644000


ethanlaj
HOBBYOP

a year ago

I'm POd


ethanlaj
HOBBYOP

a year ago

Spent an hour messing with stuff


a year ago

from your deploy logs -

RuntimeError: Either 'SQLALCHEMY_DATABASE_URI' or 'SQLALCHEMY_BINDS' must be set.

and unless I'm blind, you do not have either of them set


ethanlaj
HOBBYOP

a year ago

app.config["SQLALCHEMYDATABASEURI"] = os.getenv("HHDATABASEURL")


ethanlaj
HOBBYOP

a year ago

There was an extra space after URL which might be causing the issue


a year ago

that could do it


ethanlaj
HOBBYOP

a year ago

of course it was


a year ago

just wanna let you know that you are subjecting yourself to egress fees and slower networking by having the database in a separate project and connecting to it via the public network


ethanlaj
HOBBYOP

a year ago

hmm, how would I avoid that?


ethanlaj
HOBBYOP

a year ago

This is kinda weird but I have a singular database that is connected to by multiple projects


a year ago

🙂


ethanlaj
HOBBYOP

a year ago

Because, spinning up 5 different database instances is crazy expensive


a year ago

not ideal tbh, you'd want an induvial database in each project


ethanlaj
HOBBYOP

a year ago

too much $$


ethanlaj
HOBBYOP

a year ago

ever since they moved the DBs over to containerized


a year ago

you pay in egress and slower networking


a year ago

databases have always been ran in containers though? im not sure what you mean, sorry


ethanlaj
HOBBYOP

a year ago

Awhile back there was some old version of databases and they had to get everyone to migrate


a year ago

yeah they where still containers, we just didnt charge for egress or storage back then


ethanlaj
HOBBYOP

a year ago

Since then it was pretty cheap to run DBs per project, but since then I combined the databases into a singular one


ethanlaj
HOBBYOP

a year ago

hmm


a year ago

postgres uses much less idle resources btw


a year ago

im telling you this because i've seen too many people ask the "why do i have a $200 in egress my application doesnt get much traffic" question and i dont want that to be you


ethanlaj
HOBBYOP

a year ago

Maybe I am missing something

1323702203390627800


ethanlaj
HOBBYOP

a year ago

Is there a cap?


ethanlaj
HOBBYOP

a year ago

oh


ethanlaj
HOBBYOP

a year ago

new billing period


ethanlaj
HOBBYOP

a year ago

1323702378452750300


a year ago

$200 was just an example, you are connecting to the database publicly, theres always the possibility of some rouge code generating a lot of traffic to your database


ethanlaj
HOBBYOP

a year ago

Oh I'm actually doing this a lot lol


ethanlaj
HOBBYOP

a year ago

Example: 98e650c9-d0c2-42e7-9e30-641d0e0cabbf

Connects to Redis through its public URL even though I have them in the same instance


a year ago

the potential for a large egress bill and the much slower networking is not worth the immediate cost savings of a single separate database


ethanlaj
HOBBYOP

a year ago

I mean, at that point I could just move everything to a singular project


a year ago

thats clutter though and not scalable


a year ago

you hardcoded the url to the public url for redis


ethanlaj
HOBBYOP

a year ago

$5/mo for each database vs my current $0.22 in egress usage


ethanlaj
HOBBYOP

a year ago

That's fine, these are all just for my portfolio


a year ago

like i mentioned, there is always the possibility your code does something and generates a lot of egress to the database, many such cases


a year ago

of course you do what you think is best, i just don't want us to have to tell you that you indeed need to pay that random unexpected $200 bill for egress


ethanlaj
HOBBYOP

a year ago

I appreciate the insight


ethanlaj
HOBBYOP

a year ago

I'll work on switching stuff over


a year ago

to postgres? 😉


ethanlaj
HOBBYOP

a year ago

Maybe 😂


a year ago

your mysql idles at ~500mb of memory with 410mb of used volume, i have a postgres database that has ~7gb of used volume and idles at 105mb.


a year ago

maybe thats enough to convince you


ethanlaj
HOBBYOP

a year ago

Btw, is this how I would create a proper reference?

When I click add, the template gets replaced with the actual URL

1323705161234911200


ethanlaj
HOBBYOP

a year ago

I'll start converting 🫡

Luckily most of these are using Sequelize or other ORMs so I should be able to just switch the connector, but I think there's a couple projects that are a little more involved


ethanlaj
HOBBYOP

a year ago

And some that require a data migration unfortunately :/


a year ago

!s


Status changed to Solved brody about 1 year ago


Loading...