Open volodymyr-sch opened 2 months ago
try change to
volumes:
-
type: bind
source: ./mongo-init.js
target: /docker-entrypoint-initdb.d/mongo-init.js:ro
try change to
volumes: - type: bind source: ./mongo-init.js target: /docker-entrypoint-initdb.d/mongo-init.js:ro
Unfortunately, it didn't help. The file is still being treated as a directory, and nothing has changed.
@volodymyr-sch 1) ok first save file somewhere 2) delete the entry from the storages tab 3) then go back to compose change to this
volumes:
-
type: bind
source: ./mongo-init.js
target: /docker-entrypoint-initdb.d/mongo-init.js:ro
contents: |
test
4) save and go back to storages tab 5) remove the word test and paste in actual contents 6) save
@volodymyr-sch
- ok first save file somewhere
- delete the entry from the storages tab
- then go back to compose change to this
volumes: - type: bind source: ./mongo-init.js target: /docker-entrypoint-initdb.d/mongo-init.js:ro contents: | test
- save and go back to storages tab
- remove the word test and paste in actual contents
- save
That didn't help either; the file was still treated as a directory. I also tried to handle it manually by:
/data/coolify/applications/gg4o4w4ko4okc00cwwso4kg8# ls
README.md docker-compose.yaml mongo-init.js
...
/data/coolify/applications/gg4o4w4ko4okc00cwwso4kg8# cat mongo-init.js
//Shows actual content so changes were appied
const dbName = process.env.DATABASE_NAME;
const dbUser = process.env.DATABASE_USER;
const dbPassword = process.env.DATABASE_PASS;
db = db.getSiblingDB('admin');
try {
db.createUser({
user: dbUser,
pwd: dbPassword,
roles: [
{ role: 'readWrite', db: dbName },
{ role: 'dbAdmin', db: dbName }
]
});
print(User ${dbUser} created successfully in admin database with access to ${dbName}
);
} catch (error) {
if (error.message.includes('already exists')) {
print(User ${dbUser} already exists. Skipping creation.
);
} else {
print('Error creating user:', error.message);
throw error;
}
}
- I then redeployed without removing storage, but there were no changes in behavior.
<img width="771" alt="image" src="https://github.com/user-attachments/assets/6234c5bf-9d22-4310-97fd-30cb992e564a">
Description
I'm encountering an issue with MongoDB initialization in my Coolify deployment via Docker compose. The mongo-init.js script is not executing during startup, apparently because it's being interpreted as a directory rather than a file.
Minimal Reproduction (if possible, example repository)
Here is my docker-compose file:
Exception or Error
By checking the file in the path:
Version
v4.0.0-beta.325
Cloud?