Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

docker-entrypoint.sh not using correct port for first startup #440

Closed
Mrc527 opened this issue Dec 3, 2020 · 5 comments · Fixed by #443
Closed

docker-entrypoint.sh not using correct port for first startup #440

Mrc527 opened this issue Dec 3, 2020 · 5 comments · Fixed by #443
Labels
question Usability question, not directly related to an error with the image Request Request for image modification or feature

Comments

@Mrc527
Copy link

Mrc527 commented Dec 3, 2020

Hello,

I'm trying to setup a mongo container in AWS ECS on Fargate.

As you may know, Fargate forces all the containers of the same "task" to map ports on localhost. Long story short, if you run a complex environment with plenty of containers, all of them must serve on different TCP/UDP ports.

So, now, let's imagine I want to have two mongo containers in the same task. I need to have those containers running in two different ports.

Easy, just add the --port 1234 and --port 1235 to the "command" section of the docker-compose file.

But unfortunately that's not enough.

When you start the container via docker-entrypoint.sh, the scripts temporarily starts the container on the default port for adding users and stuff.

In such a moment, the second container will find the port busy and fail.

As a workaround I currently do:
entrypoint: ["bash","-c","sed -i 's/27017/50040/' /usr/local/bin/docker-entrypoint.sh && /usr/local/bin/docker-entrypoint.sh --port 50040" ]

Clearly that's not a nice fix.

I propose, the docker-entrypoint.sh should randomly select the temporarily port, to minimise the probability of a conflict.
Even better would be to first check if the selected port is available, otherwise try with a different one.

Thanks!

@wglambert wglambert added question Usability question, not directly related to an error with the image Request Request for image modification or feature labels Dec 3, 2020
@wglambert
Copy link

Similar to #437

@yosifkit
Copy link
Member

yosifkit commented Dec 4, 2020

I propose, the docker-entrypoint.sh should randomly select the temporarily port, to minimise the probability of a conflict.
Even better would be to first check if the selected port is available, otherwise try with a different one.

Selecting a random port will just make the failure non-deterministic since it'd still be able to pick a used port; checking for a port would be subject to a race condition, since the shell script isn't opening the port, mongod does.

Fortunately, it looks like we can switch to only use the unix socket during the temporary init, but this will break users that are using mongo and not "${mongo[@]}" in their shell scripts.

@tianon
Copy link
Member

tianon commented Dec 4, 2020

There's a potential solution to this over in #443. 👀

@rhaoio
Copy link

rhaoio commented Nov 8, 2024

Is there a clean solution to this problem? I have a scenario using network_mode: host which causes a similar problem as 27017 may be used already.

@tianon
Copy link
Member

tianon commented Nov 8, 2024

The easiest solution in that case would be to skip our entrypoint entirely and perform your own initialization (if needed).

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
question Usability question, not directly related to an error with the image Request Request for image modification or feature
Projects
None yet
Development

Successfully merging a pull request may close this issue.

5 participants