Bash script wait depended commands processes

I am fairly new in bash scripting. I need to use bash script for manage my microservices, so these services need build and deploy(on docker).

So I have commands like that :

  • How to check if a process is running inside docker container
  • bash: child setpgid (5870 to 5870): No such process on docker
  • How to do a custom hostname (URL) to site in docker container in Ubuntu 16.04?
  • Rancher: always deploying to new stack
  • boot2docker / docker “Error. image library/.:latest not found”
  • How to add Dockerfile to a docker registry page?
  • #!/bin/bash
    mvn clean
    wait $!
    mvn package
    wait $!
    #Some if elses here
    sudo docker build -t myService . &
    wait $!
    #Some if elses here
    sudo -S docker run -d -name myService myService &
    

    So as you see(a little part of script, i am grouping depended commands in functions),commands need to wait previous depended commands like that. But wait $! command doesn’t look nice after all command.

    Are there any approaches for this situations?(I am open other approaches instead of bash scripting if it is handy solution. Btw services are node and java services seperated, so I need to start all of them with one bash script.)

  • How to access a docker container from another machine than its windows host?
  • How to specify different .dockerignore files for different builds in the same project?
  • Running a simple webserver in Docker?
  • Docker when deployed on marathon is failing continously
  • Docker Images Hierarchy
  • docker: gitlab + traefik & port 22
  • One Solution collect form web for “Bash script wait depended commands processes”

    To automatically wait for a command, just don’t add a & to them:

    sudo docker build -t myService .
    sudo -S docker run -d -name myService myService
    

    This waits for sudo docker build -t myService . to completely exit before continuing with sudo -S docker run -d -name myService myService. It then waits for sudo -S docker run -d -name myService myService to completely exit before continuing with anything else.

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