refactor the code for docker connection