Home Calling several services in one docker-component file in turn
Reply: 0

Calling several services in one docker-component file in turn

user3652
1#
user3652 Published in April 21, 2018, 4:00 am

help me please, I have one docker-compose a file. It has 2 test services and 2 workers. And there is a script. I need to make a sequential call: i.e. at first when I make docker-compose up 2 test services (post-service-test and rabb-service-test) should go up, then a script should run (it builds the application based on these running test services), then I need to stop and delete these test services and only then I have to raise 2 working services (post-service and rabb-service). Can you please tell me how to do this, having this kind of docker-compose file:

     version: '3'
services:
  postgres:
    container_name: post-service
    image: postgres:9-alpine
    environment:
      - POSTGRES_USER=${POSTGRES_USER}
      - POSTGRES_PASSWORD=${POSTGRES_PASSWORD}
    volumes:
      - ${PWD}/db_migration/cdp_dump.sql:/home/postgres/cdp_dump.sql
    ports:
      - "5432:5432"
    networks:
      - work_network
    labels:
      container_group: work_env


  rabbitmq:
    container_name: rabb-service
    image: rabbitmq:3-management-alpine
    environment:
      - RABBITMQ_DEFAULT_USER=${RABBITMQ_DEFAULT_USER}
      - RABBITMQ_DEFAULT_PASS=${RABBITMQ_DEFAULT_PASS}
      - RABBITMQ_DEFAULT_VHOST=${RABBITMQ_DEFAULT_VHOST}
    ports:
      - "15672:15672"
      - "5672:5672"
    depends_on:
      - postgres
    networks:
      - work_network
    labels:
      container_group: work_env


  postgres_test:
      container_name: post-service-test
      image: postgres:9-alpine
      environment:
        - POSTGRES_USER=${POSTGRES_USER}
        - POSTGRES_PASSWORD=${POSTGRES_PASSWORD}
        - POSTGRES_DB=${POSTGRES_DB}
      networks:
        - test_network
      labels:
        container_group: test_env


  rabbitmq_test:
      container_name: rabb-service-test
      image: rabbitmq:3-management-alpine
      environment:
        - RABBITMQ_DEFAULT_USER=${RABBITMQ_DEFAULT_USER}
        - RABBITMQ_DEFAULT_PASS=${RABBITMQ_DEFAULT_PASS}
      depends_on:
        - postgres_test
      networks:
        - test_network
      labels:
        container_group: test_env


networks:
    work_network:
    test_network:


  application:
    container_name: build
    image: openjdk:8-jdk
    environment:
      - POSTGRES_HOST=${POSTGRES_HOST}
      - POSTGRES_DB=${POSTGRES_DB}
      - POSTGRES_USER=${POSTGRES_USER}
      - POSTGRES_PASSWORD=${POSTGRES_PASSWORD}
      - RABBITMQ_HOST=${RABBITMQ_HOST}
      - RABBITMQ_DEFAULT_USER=${RABBITMQ_DEFAULT_USER}
      - RABBITMQ_DEFAULT_PASSWORD=${RABBITMQ_DEFAULT_PASS}
    volumes:
      - ${project_home}:/root
    command:
    /bin/bash < build_script

Maybe I wrote the script incorrectly in a file? The script itself looks like this and it's working, if you run it separately. But I need to add it here so that everything does docker-compose. The script itself:

  docker run --name build -i --net test-network \
-v ${project_home}:/root \
-e POSTGRES_HOST=${POSTGRES_HOST} \
-e POSTGRES_DB=${POSTGRES_DB} \
-e POSTGRES_USER=${POSTGRES_USER} \
-e POSTGRES_PASSWORD=${POSTGRES_PASSWORD} \
-e RABBITMQ_HOST=${RABBITMQ_HOST} \
-e RABBITMQ_DEFAULT_USER=${RABBITMQ_DEFAULT_USER} \
-e RABBITMQ_DEFAULT_PASSWORD=${RABBITMQ_DEFAULT_PASS} \
openjdk:8-jdk /bin/bash < build_script

And another question: can I do such commands as docker stop post-service-test, docker rm post-service-test, docker stop rabb-service-test, docker rm rabb-service-test (stop and delete test services) to execute separately, and also to place in docker-compose or it is impossible?

Thank you in advance !

You need to login account before you can post.

About| Privacy statement| Terms of Service| Advertising| Contact us| Help| Sitemap|
Processed in 0.304551 second(s) , Gzip On .

© 2016 Powered by mzan.com design MATCHINFO