MongoDB with volume fails to authenticate after duplication (environment creation)
Hello there,
When i create a new environment, already containing a MongoDB instance on the main env, it tries to duplicates it, without any ENV Variables (?), and once i import all the variables from de main environment, the MongoDB instance fails to authenticate (on the "Data" tab of the MongoDB service).
I'm a bit confused of the "duplication" behavior, without env vars, and i don't understand why it does not work after i import the variables as well.
Thanks for helping !
Solution:Jump to solution
- in the main environment's mongodb service set a service variable
MONGO_DBPATH
to ${{RAILWAY_VOLUME_MOUNT_PATH}}
- cancel the popup
- in the mongodb service settings set this start command /bin/sh -c "docker-entrypoint.sh mongod --dbpath ${MONGO_DBPATH} --ipv6 --bind_ip ::,0.0.0.0"
- don't cancel the popup
- create your new environment in the projects settings...21 Replies
Project ID:
fa4f3b3c-8eb7-43a6-a995-0619ad7c212c
fa4f3b3c-8eb7-43a6-a995-0619ad7c212c
if you want to create a duplicate environment with all variables the same, you want to use forked environments
https://docs.railway.app/develop/environments#forking-and-merging-environments
Thanks for the reply, i'm not really looking to completely "clone" my environment, just create independant environments "prod, dev, preprod", with the same architecture but with their own data.
The problem is the behavior of the MongoDB service with i create a new environment, would you be alright to explain what I need to do with the variables to make it work ?
though i understand they confusion, the reason why the database couldn't be connected to even after adding all the variables back to it is likely because it was already deployed and initialized itself with no variables, this seems like it messed something up internally in the container. in my opinion that flow should not auto deploy anything and instead ask you to setup the variables and then give you a deploy now button for when you have all variables setup
Alright ! Thats what i was testing and it seems to be the case, because i also have a volume connected to the service. Problem is if i decide to delete the volume to restart the deployment with the variables, the volumes of all the other environments get deleted as well π
Is there a possibility to reset a volume on one environment only ?
let me see if i can come up with a flow to solve this
The solution i came up with is to stop de deployment as fast as possible to not write anything on the partition, then import the variables, then re-deploy
thats what im thinking, but doing that is hard, docker images deploy fast and mongo could write garbage to the volume before you are able to abort
It would be great to have a "Deploy" button floating top right (or any other place) on the dashboard, to click when the user finish to setup the environment
Yes, had to do it 3 times before a success
yeah and not have anything auto deploy, because 9 times out of 10 (made up number) a service will fail without any variables set
Thanks for the help ! Can I mark this thread as solved ?
not solved yet, i havent come up with a flow that works every time yet
Oh you are still on it, thanks !
of course
Solution
- in the main environment's mongodb service set a service variable
MONGO_DBPATH
to ${{RAILWAY_VOLUME_MOUNT_PATH}}
- cancel the popup
- in the mongodb service settings set this start command /bin/sh -c "docker-entrypoint.sh mongod --dbpath ${MONGO_DBPATH} --ipv6 --bind_ip ::,0.0.0.0"
- don't cancel the popup
- create your new environment in the projects settings
- the mongodb service in this new environment will crash after a bit, thats expected
- import all the variables one by one and cancel the redeploy popup on every variable import except the very last
- once the service redeploys from adding the last variable everything should work as expectedcertainly not very good dx, but it does work every time
@Melissa - room for dx improvements when creating new environments
Alright so if i understand well, the env var added to the docker entrypoint serve as a test to fail if the env vars are not imported
great solution !
yeah more or less, not pretty but it works
thanks both, apologies for the poor DX in the current state. we are working to make this experience better! i have referenced this thread in that project
Thanks a lot ! It's already insane that the UX of railway is better that GCP xd