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.

  • Zero downtime deploy to azure as an docker container
  • Java Maven Project Docker Integration Tests
  • How do you use docker-compose from a Gitlab Registry on DigitalOcean?
  • Gitlab CI with Ionic2 and dockerfile for generating apk
  • How can I use gitlab and/or docker for my web app?
  • ERROR: Registering runner. forbidden (check registration token)
  • 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.

  • kubernetes production deploy docker multi-node or ubuntu bare metal?
  • kubernetes : PTY allocation request failed
  • Docker mysql image - move internal container DB to the volume
  • Kubernetes pod not binding volumes to container
  • pip install doesn't work correctly in docker
  • How to generate a certificate for AWS EC2 instance part of AWS ECS ( Docker)
  • 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.