I have two Dockerfiles, one for a database, and one for a web server. The web server's Dockerfile has a RUN
statement which requires a connection to the database container. The web server is unable to resolve the database's IP then errors out. But if I comment out the RUN
line, then manually run it inside the container, it successfully resolves the database. Should the web server be able to resolve the database during its build process?
# Web server
FROM tomcat:9.0.26-jdk13-openjdk-oracle
# The database container cannot be resolved when myscript runs. "Unable to connect to the database." is thrown.
RUN myscript
CMD catalina.sh run
# But if I comment out the RUN line then connect to web server container and run myscript, the database container is resolved
docker exec ... bash
# This works
./myscript