I have a web application image (web) and a database image (db) that needs to be run using docker-compose.

Since my web app needs a content management system to be installed as well, I would like to make an image out of that (web-cms-db) and use that instead.

However, the problem is that how do build an image which has a container (i.e it should be running) as a dependency? I need to be able to reach the service.

docker-compose seems to have a build option so I tried using that, but the only problem is that the database container won't be running during the build phase!

I think I can do something using the networking layer, but I was wondering if I could use docker-compose for this as the only additional requirement is to have the container running.

version: "3.1"
    image: database
      context: ../web
      dockerfile: Dockerfile
    image: web-cms-local-db-image

Maybe I could create a dummy docker-compose up that leverages the networking?

  • I think this question is pretty similar stackoverflow.com/questions/52788472/… – Nishant Apr 12 at 12:49
  • 1
    You mean you need to have a RUNNING service when BUILDING the other? – Pierre B. Apr 15 at 10:16
  • @Pierre B., In one sentence, YEAH. I believe docker-compose didn't have a need for this; so they don't support it. – Nishant Apr 15 at 11:07
  • 1
    I don't think so either - why does your Web image build process requires the Database container to be running? Usually when building images you only need to download external packages to install in your image. – Pierre B. Apr 15 at 13:06

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Browse other questions tagged or ask your own question.