Docker-compose run service if another service status is 0 (success)

I am pretty new to Docker and Docker compose.

I want to use docker compose to test my project and publish it if tests are ok. If tests are failed, it should not publish the app at all.

  • How to avoid redundancy and time loss when re-building images during development?
  • Run MongoDB in a Docker container with no volumes
  • Unable to pull docker image with concourse - Verifying Checksum error
  • How to update code from git to a Docker container
  • docker commands not executed properly in TeamCity
  • Trouble developing on mirrored, but separate, production environment
  • Here is my docker-compose.yml

    version: '3'
    services:
      mongodb:
        image: mongo
      test:
        build: 
          context: .    
          dockerfile: Dockerfile.tests
        links:
          - mongodb
      publish:
        build:
          context: .
          dockerfile: Dockerfile.publish
      ?? # I want to say here that publish step is dependent to test.
    

    After that, in my testAndPublish.sh file, I would like to say:

      docker-compose up
    
      if [ $? = 0 ]; then  # If all the services succeed
          ....
      else
          ....
      fi
    

    So if test or publish steps are failed, I am not going to push it.

    How can I build step like processes in docker-compose?
    Thanks.

  • Docker: setctty operation not permitted
  • Nightmare.js with Docker
  • Writting empty object with socket.io
  • Faster Google App Engine Managed VM deploys (Python compat env)?
  • Challenges in upgrading Docker components
  • move default docker container to another place on the disk
  • One Solution collect form web for “Docker-compose run service if another service status is 0 (success)”

    I think you’re trying to do everything with docker-compose which is the wrong way around.

    When it comes to CI (f.e. Travis or CircleCI) I always make my workflow as follows:

    • let’s say you have a web node and database node
    • In travis.yml or circle.yml at the install step I always put things like f.e. docker-compose run web npm install and others
    • at the test step I would put docker-compose run web npm test or something similar like docker-compose run web my-test-script.sh, that way you’ll know that the tests will run in the declared docker environment, if they fail this step fails and the whole test step in the CI fails which is desired
    • at the deploy step I would run some deploy.sh script which will build the image from Dockerfile (the one that web uses) and push it for example to Docker Hub.

    This way your CI test routine still depends on specific Docker environment but the deploy push (which doesn’t need Docker) is kept separately from the application which makes it more convinient imho.

    Docker will be the best open platform for developers and sysadmins to build, ship, and run distributed applications.