Docker Community Forums

Share and learn in the Docker community.

Changing contents of configuration file on start of container


(Shaun0024) #1

Hi all,

I have two containers that I need to link together, one is a Tomcat application and another is the engine that it needs to connect to.

I can link both containers successfully and I have verified that there is no connectivity issues between both. However, one of the configuration files on the Tomcat container doesn’t seem to be able to resolve the hostname of the engine container, although ping of the hostname works fine. So I need to change the hostname to the IP of the engine container each time.

I don’t know if this is possible but I’m trying to find a way to automatically modify this configuration file on the Tomcat container with the IP address of the engine when I run the container. Is this possible?

I was thinking of putting a script inside the container with an sed command that would replace it either automatically or based on some value / parameter that is sent with the docker run command.

Any advise would be much appreciated. I’m new to Docker so please forgive me if this has been asked before, I couldn’t find anything matching what I wanted to do, maybe because I searched for the wrong terms.

Regards,
Shaun


(David Maze) #2

I’m not totally clear what’s going on here. How are you connecting the containers? (docker run --link?) How are you testing that you can’t resolve the hostname? (dig? nslookup?) What’s the significance of ICMP working (ping)?

If I was going to guess, I’d guess that Tomcat isn’t doing a good job of honoring /etc/hosts, but if you run both containers on the same private Docker network, Docker will provide an internal DNS service (and you won’t need --link).

Yes, via an ENTRYPOINT script in your Dockerfile; but if you can resolve the IP address to a host name programatically at container startup time, it seems like the application should be able to do the same thing too?


(Shaun0024) #3

Hello David,

Yes, I am linking both containers together using ‘docker run link’ and I can see that it has created the host entries in the Tomcat container. The significance of ICMP is that I wanted to see if a ping to the hostname works instead of an IP, and so it does work.

There is just one entry inside the configuration file of this Tomcat app that does not seem to be able to resolve this very same hostname that works on ping. I know it does not work because it keeps throwing up an ‘unknownhost’ error and the minute I change this entry in the configuration file from a hostname to an IP, it works without a problem.

So, like you said, maybe it’s something to do with Tomcat but I’ve not encountered this when I am using this in a regular virtual machine. I’ll try ENTRYPOINT and maybe include a script there to change this when I start the container.