Search code examples
linuxbashdockerpipeecho

In linux, how does the echo and pipe work with docker?


I'm confused about the following bash scripting code in my company's project:

scorm_init()
{
    docker_start "scorm"
    scorm='/tartar/scorm-engine/. tartar container-init'
    echo $scorm | docker exec -i tartar--scorm /bin/bash
}

backend_init()
{
    docker_start "backend"

    # setup django backend user ([email protected] :: engineering)
    backend="
    from django.contrib.auth.models import User;
    User.objects.filter(email='$LOCAL_SUPERUSER_EMAIL').delete();
    User.objects.create_superuser('$LOCAL_SUPERUSER_EMAIL', '$LOCAL_SUPERUSER_EMAIL', '$LOCAL_SUPERUSER_PASSWORD');
    "
    log "Creating backend admin user: $LOCAL_SUPERUSER_EMAIL..."
    echo $backend | docker exec -i tartar--backend python manage.py shell

}

How does echo ... | work with the following docker exec ... command? I understand that pipe | feeds the output of the beforehand operation to the input of the following operation. But how does it work in this case?


Solution

  • The -i option to docker exec indicates that stdin should be piped into the container process. To the value of $scorm is sent as input to the /bin/bash process launched inside the container and it gets run as if you typed it on the bash shell.