skip to Main Content

I’m creating a bash script to loop all my packages, and execute their tests.

testAll () {
    dir=~/packages;

    for f in "$dir"/*
    do
        cd $f;
        sail down;
    done;

    for f in "$dir"/*
    do
        cd $f;
        sail up;

        if MYSQL is EXIST; then
            artisan migrate:fresh --seed;
        fi
        test-all;
        sail down;
    done;

    cd ..;
}

I need to check if mysql is exist, so I can execute "migrate" command. I could only find functions that display the container, but I need a boolean. So, how can I do that.

Thanks in advance.

2

Answers


  1. Chosen as BEST ANSWER

    The solution I came up is the following.

    if [ ! -z $(docker ps --filter expose=3306 --format "{{.ID}}") ];
    then
        # code ...
    fi
    

  2. You can try this:

    docker inspect --format='{{.State.Status}}' your_container
    

    This will return docker status, running, up, and exited.

    Login or Signup to reply.
Please signup or login to give your own answer.
Back To Top
Search