Hi guys, I need some of your advice or if you have any other idea about a problem I have found today.
Docker API provides a method to wait until the container is started, so basically you use wait function and you wait until docker server sends you that the container is up, and then the method is unblocked and you can be sure that you can use it. The problem with this method is that it only works if the server you requires from container (let’s say a MongoDB) is started in background and as daemon. But in general java servers cannot use this approach inside Docker; they must start in foreground. If you see Wildfly container, Tomcat container and so on you will see that they are executed using CMD operator. So server is started on foreground and the server can start correctly. If you do not this, Docker container is executed but don’t start the server.
So wait approach doesn’t work because the container never ends. So we need another approach. My first idea was to open a socket on required host and port and if an exception is thrown I retry. But this approach has one problem and is that when docker is starting up it does some port forwarding so when this ping is executed the ping returns true so it seems that server is is up, but this is not true, Tomcat in that case is not up and the file cannot be deployed. I think that this is because Docker container opens the port to do the port forwarding and although server is not up the socket can be opened so no exception is thrown. I know that it is a bit difficult to explain, but basically if I do an sleep it works but if I add the approach it doesn’t work and Arquillian says that cannot deploy the deployment file because server is not up.
So I have thought that maybe user should be able to set which approach to use to wait until docker is up.
- Native wait: which is the native way of waiting
- Sleep: which is an fix sleep time
- Command Line inspect: you add a reg exp. and until this regular expression does not return true from the console log of docker container.
So this is the problem, WDYT? Any new idea?