Prevent skip in docker-compose

I have a docker-compose.yml for a Django web app with a backend. It looks like this:

version: '2'

    image: # special image
      - "1433:1433"
      PASSWORD: "*********"

    build: .
    command: python runserver
      - "8000:8000"
      - db

When I run sudo docker-compose build, the first line of output says

  • Unable to connect the client to the server using Docker COntainers
  • docker-py: how can I check if the build was successful?
  • Pass environment variables from docker-compose to container at build stage
  • How to configure docker to be able to have internet access via wireless connection?
  • running django worker and daphne in docker container
  • intel pin with docker
  • db uses an image, skipping. 
    Building web.

    I need the db image to be built before web.

    How can I make the db image get built first?

  • How do I run a python script with Tensorflow running in a Docker on Windows?
  • Get internal IP address of Docker container using Ansible
  • How to know if a service container is ready for connections?
  • Docker: use private layers without running instance of registry
  • Should I use docker-compose start up or run?
  • Docker: How Do I remove all images used to build a container?
  • One Solution collect form web for “Prevent skip in docker-compose”

    You can start your db container in Detached mode before building web:

    $ docker-compose up -d db
    $ docker-compose build web

    Though, this seems like an anti-pattern. I would recommended that you keep the build process for web as generic as possible, and instead use environment variables or command arguments to accomplish this.

    For instance, if you need to pass the same configuration values to both web and db, you could accomplish this using an env_file:

    # db_credentials.env

    And in your docker-compose.yml file:

        # ...
        env_file: db_credentials.env
        # ...
        env_file: db_credentials.env
    Docker will be the best open platform for developers and sysadmins to build, ship, and run distributed applications.