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'

services:
  db:
    image: # special image
    ports:
      - "1433:1433"
    environment:
      PASSWORD: "*********"

  web:
    build: .
    command: python manage.py runserver 0.0.0.0:8000
    ports:
      - "8000:8000"
    depends_on:
      - db

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

  • Run Jenkins master and slave with Docker
  • Difference between 'image' and 'build' within docker compose
  • how to pass a --login into docker build
  • distributed tensorflow using docker
  • Expose docker daemon on other adress on windows
  • docker Django runserver blocks binaries connecting to MySQL DB
  • 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?

  • Unrecognized import path “main/testPackage” when running Go image
  • How to auto scale docker containers in a regular cloud server?
  • Why are docker layer IDs now hidden with the new storage model?
  • How do you run an Openshift Docker container as something besides root?
  • Using a any part in external_url causes the server to be unreachable on docker and docker-machine
  • Docker container for Laravel: PHP 7.x on CentOS 7.x
  • 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
    USER="django"
    PASSWORD="********"
    DATABASE="django_db"
    

    And in your docker-compose.yml file:

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