Release Go app with Docker and godotenv
I have this function that I use on my server setup to load the .env variable and on my main.go I do a simple load
Locally it works but when hosting with a Dockerfile the app crashes because it can't load the env variable
The app is deployed but eventually crashes with
Any clue ? I know this isn't a railway problem more but any feedback would be appreciated.
7 Replies
Project ID:
N/A
N/A
I like the part where you said "we copied the .env file" but then you never copied the .env file
also, you don't need a .env file anyway, that's what service variables are for
I know this isn't a railway problemthat's a breath of fresh air honestly, finally someone not blaming the platform when something goes wrong, I like you
Platform is great. I just haven’t touched Docker and Docker compose since school. It’s a skill issue. The reason why I dont copy the .env is because it’s supposed to not be a “good” practice to do so… but I’m far from being on my comfort zone on this to know for sure.
it's my opinion that using a .env file to store credentials for public facing services (like a railway postgres for example) is a terrible idea (even locally) an .env file is plaintext after all, and throughout my time here I have seen many users database credentials and api keys just hanging around in their repos when they share them so I can help them.
so would you be interested in totally removing your dependency on your .env file in favour of railway service variables, and the railway cli's run and shell functionality that can securely pull credentials from railway to run your app locally without ever having to write credentials to a file
I did this:
So the dev.env is only applied in development mode. Just a workaround for this api that I actually want to have in production and deploy a mobile / web app asap.
but you dont need a .env file anywhere, locally or on railway