Docker Community Forums

Share and learn in the Docker community.

Build container and startup before next container builds


(Franksdocker) #1

I want to dockerize an application and run into the following problem:

  • Container A:
    • Installed RPM1

All fine.

  • Container B:
    • Installed RPM2

In RPM2 in the postinstall script it is checking that the Service in Container A is running with an endless while loop
as it is trying to register itself there and updating the config. (A is some kind on central config-server)

  • When i use docker-compose the Container A isnt started directly but only after all builds are complete, so build of Container B fails. Of course i have set depends_on. Is there something available to do that ?

Other solutions i thought of:

  1. Use a shellscript with docker to build and startup Container A before building for Container B starts.
  2. Two Docker-Compose files, one for each container, but i would prefer one and use the container-linking, networking etc.
  3. Install the RPM2 with the --noscripts parameter and then put the postinstall into a RUN command of the Dockerfile. (very ugly)
  4. get the rpm changed

Any other ideas or tricks welcome. Thanks !


(Brandon Mitchell) #2

I think you’ll run into an issue building the second container since it won’t be able to see other containers on the docker networks. Doing a build in docker-compose or simply on the docker cli doesn’t connect to your volumes and networks defined in your compose file. It would be an anti-pattern to try to change this since a build should be reproducible and portable. You also don’t want configuration injected during the build, that should be maintained external from the image.

Without more specifics, I’d recommend moving the postinstall registration to the entrypoint of your container B.