1

I recently started working with docker-compose and I am running into an issue where I won't get any helpful answers while googling. So what I want to do is running 2 commands on after another. First I want to train my model which places a trained model in a folder. The second command then runs the model. However, right now both commands start together and the image is loaded twice as well as the volume is created twice.

So my question is if it is possible to run multiple commands one after another, how does that work? I wonder as well, how my trained model is put into the volume docker-compose is running on? Can I somehow set a path to that volume as an output?

My docker-compose file so far:

version: '3.3'
networks: {rasa-network: {}}
services:
  rasa:
    image: rasa/rasa:latest-full
    ports:
      - "5005:5005"
    volumes:
      - ./rasa/:/app/
    command:  run -vv -m models/test_model/ --enable-api --endpoints endpoints.yml --credentials credentials.yml
    networks: ['rasa-network']
    depends_on:
      - training
      - duckling
  duckling:
    image: rasa/duckling:latest
    ports:
      - "8000:8000"
    networks: ['rasa-network']
  training:
    build: .
    image: rasa/rasa:latest-full
    command: train --data data/ -c config.yml -d domain.yml --out models/test_model
    volumes:
      - ./rasa/:/app/
2
  • Can you run the training step offline outside of Docker, or in your image’s Dockerfile? Commented Mar 5, 2020 at 19:23
  • so I need to run the training every time before I run the other command on my server. What do you mean by "in your image's dockerfile" how would that work? Commented Mar 5, 2020 at 19:25

1 Answer 1

1

According to the documentation of depends_on, Docker compose is not able to determine the readiness of a container, so as soon as the dependencies have started, the last container will start, ignoring if the other ones are ready or not.

The workaround you could do is to do a wrapper shell script that controls that the dependencies (duckling and training) have finished doing their stuff before starting rasa. This means, if rasa needs some files from the other two containers, you can create an script to check if these files exist with a loop. If so, exit the loop and run the command you have. Otherwise, sleep some seconds and retry.

Then, the rasa command would execute only this script, for example:

command: ["./wait-for-dependencies.sh", "duckling", "training"]

You can have a look here: https://docs.docker.com/compose/startup-order/, they have made some examples for a similar use-case.

Sign up to request clarification or add additional context in comments.

1 Comment

thanks for the help! I fixed it by creating my own image file where I do the training and afterwards use that image in the docker-compose. I don't know if this is the cleanest way but it works fine for me!

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.