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

2 years 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

2 years ago

9d88d41d-d840-4ff7-9796-a4dcf88468f1


2 years ago

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


ethanlaj
HOBBYOP

2 years ago

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


2 years ago

yes they will


ethanlaj
HOBBYOP

2 years ago

HMM

1323700056347644016


ethanlaj
HOBBYOP

2 years ago

I'm POd


ethanlaj
HOBBYOP

2 years ago

Spent an hour messing with stuff


2 years 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

2 years ago

app.config["SQLALCHEMY_DATABASE_URI"] = os.getenv("HH_DATABASE_URL")


ethanlaj
HOBBYOP

2 years ago

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


2 years ago

that could do it


ethanlaj
HOBBYOP

2 years ago

of course it was


2 years 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

2 years ago

hmm, how would I avoid that?


ethanlaj
HOBBYOP

2 years ago

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


2 years ago

🙂


ethanlaj
HOBBYOP

2 years ago

Because, spinning up 5 different database instances is crazy expensive


2 years ago

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


ethanlaj
HOBBYOP

2 years ago

too much $$


ethanlaj
HOBBYOP

2 years ago

ever since they moved the DBs over to containerized


2 years ago

you pay in egress and slower networking


2 years ago

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


ethanlaj
HOBBYOP

2 years ago

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


2 years ago

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


ethanlaj
HOBBYOP

2 years 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

2 years ago

hmm


2 years ago

postgres uses much less idle resources btw


2 years 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

2 years ago

Maybe I am missing something

1323702203390627881


ethanlaj
HOBBYOP

2 years ago

Is there a cap?


ethanlaj
HOBBYOP

2 years ago

oh


ethanlaj
HOBBYOP

2 years ago

new billing period


ethanlaj
HOBBYOP

2 years ago

1323702378452750428


2 years 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

2 years ago

Oh I'm actually doing this a lot lol


ethanlaj
HOBBYOP

2 years ago

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

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


2 years 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

2 years ago

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


2 years ago

thats clutter though and not scalable


2 years ago

you hardcoded the url to the public url for redis


ethanlaj
HOBBYOP

2 years ago

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


ethanlaj
HOBBYOP

2 years ago

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


2 years 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


2 years 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

2 years ago

I appreciate the insight


ethanlaj
HOBBYOP

2 years ago

I'll work on switching stuff over


2 years ago

to postgres? 😉


ethanlaj
HOBBYOP

2 years ago

Maybe 😂


2 years 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.


2 years ago

maybe thats enough to convince you


ethanlaj
HOBBYOP

2 years ago

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

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

1323705161234911242


ethanlaj
HOBBYOP

2 years 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

2 years ago

And some that require a data migration unfortunately :/


2 years ago

!s


Status changed to Solved brody over 1 year ago


Welcome!

Sign in to your Railway account to join the conversation.

Loading...