Connecting container through mysql running on other host

Hi Team,

Kindly let me know below

  1. how to connect db (running on other host) while running container as app inside container needs DB to initialize.
  2. Checking traces for container if DB bind is successful and app is initialized properly.


If i understand you correctly, you should be able to connect to your mysql host just as if you would in a normal application, your container will be able to resolve and connect to the mysql host.

I belive your application should check if it has connected or not

Thanks Martin,
i think its not getting resolved as getting below exception
Local Port(10.0.2.x:9091) => bind()… FAILED. Error: Cannot assign requested address

Here 10.0.2.x is local host IP where I m running container and 9091 is port.

What else is using this port?
How do you start your application container?

  1. Currently in host i.e. i had checked 9091 port is not used.
    netstat -ntpl | grep 9091
  2. starting container as per below.
    docker run -it 62bba9d9cde3 /bin/bash

Exactly what gives you this error message? I thought you had problem with the mysql connection but it says HTTP SERVER PORT.

I am executing .sh file in Dockerfile which will initialize/start application while running container but while running container I can’t see any application running may be due to this exception “HTTP SERVER PORT [9091] ALREADY IN USE” if I am running this .sh file manually inside container I am getting this exception but if i am checking port then it’s say’s below.
[root@imi-hyd-rnd1 pjsip]# docker port 47503b8ee746 9091
Error: No public port ‘9091/tcp’ published for 47503b8ee746
Below is extract of Dockerfile for reference.
CMD /sss/

One more thing I m suspecting is right now under application host IP is mentioned which is used for starting application and as container doesn’t know regarding host IP that’s why this address & port conflict.
Is there any way that container should use host IP?

Okay, I don’t think we can help you unless you give us more information. Until now everything you gave us hid what you really did.

  1. The topic is about MySQL connection and it is still not clear to me if we are talking about two different issues or you realized the problem is not what you first thought
  2. You shared an error message but we don’t know what throws that error message, except that it is an “application”.
  3. The IP address in the error message is 10.0.2.x but you mentioned later that you checked the port on the host with an other IP address (
  4. When you shared how you start the container, you used an image ID, so I still cannot tell what that “application” is.
  5. Because I don’t know what throws that error message, I asked you “Exactly what gives you this error message?” because it can help to understand why that error happened. I can only tell that it is an HTTP server, but you could run an HTTP server with HTTPD, NginX, Python, NodeJS, PHP, etc… I know the output of some of them, but I don’t recognize your error message.
  6. Even when you checked the port of a container, you used an ID again so we still don’t have any clue.
  7. Your command is “”, still no clue :slight_smile:

Your last post I just don’t understand. Maybe it’s just me, but could you share what you are trying to do from the beginning step by step, providing us more information with commands and everything you are allowed to share? If you are not allowed to share something, for example the name of the application or the type of the HTTP server, please tell us that so we will not ask you about that again.

Hi Rimelek,

Yes, I do agree but after trouble shooting DB connectivity is resolved automatically by container and also http exception was due to host IP not getting bind to container, using --network=“host” flag while running container sorted problem, now both db & http exception is sorted out, thanks.

generally while running container application should start automatically (here application defined in Docker file is but it my case it’s not getting started, if I am starting .sh file manually from container it’s starting properly below are details. Kindly look into it.

FROM centos:centos7.9.2009
RUN mkdir /pjsip
WORKDIR /pjsip
COPY davincisip /pjsip
RUN mkdir /usr/local/lib64/imidbconnector1
ADD imidbconnector1 /usr/local/lib64/imidbconnector1
RUN mkdir /usr/lib64/mysql
ADD mysql /usr/lib64/mysql
COPY /usr/lib64/
RUN cd /usr/lib64 && ln -s && ln -s && ln -s && ln -s
#RUN dnf install net-tools
CMD /pjsip/

starting container
docker run -it --network="host" pjsip /bin/bash

First of all, thank you for sharing the Dockerfile. I edited your post so the code is formatted properly. Please, use </> button when you write your message to highlight codes. If you don’t do that, the markdown filter can totally ruin your code so we don’t understand it.

Seeing your code I realized where your current “adventure” started so I leave it here for others before they ask why you copy binaries from the host, although I wouldn’t do that either and it can cause issues if you don’t do it right.

So if I understand well, you solved everything. That’s great :slight_smile:

Hi Rimelek,

Is I am doing something wrong by copying code from host to container? here already compiled code is there which I am mentioning in mentioning in .sh and same .sh file i am using to start app. i don’t know if I am doing something wrong, need your assistance.

Also further to last post currently git/svn repository I am not preferring due to some security concern, if .sh file I am able to start properly manually inside container then why it’s not getting initialized automatically is main thing, if I am doing something wrong please let me know so that this problem can be sorted out.

I wouldn’t start a conversation about copying libraries here but It is clearly something nobody does. You install the libraries using apt or dnf for example or build them from source code. If you copy a library to the wrong place then nothing works…