dockervespadocker-exec

Command works inside a docker container but fails with docker exec


I'm using containerized Vespa.ai DB, and I want to execute the following commands from the host:

  1. vespa-stop-services
  2. vespa-remove-index
  3. vespa-start-services

If I execute the following vespa-stop-services && vespa-remove-index && vespa-start-services from my shell after I attach the container, it works fine. But when I use docker exec it fails.

I tried the following commands:

docker exec bash -c 'vespa-stop-services && vespa-remove-index && vespa-start-services'

docker exec bash -l 'vespa-stop-services && vespa-remove-index && vespa-start-services'

The only way I successfully managed to execute those commands, is when I execute them sequentially, which I would like to avoid:

docker exec bash -l 'vespa-stop-services'

docker exec bash -l 'vespa-remove-index'

docker exec bash -l 'vespa-start-services'

What am I doing wrong? Thanks in advance!


Solution

  • You need to specify the location of these commands when running from the parent host system

    The following works/should work :

    docker exec vespa bash -c "/opt/vespa/bin/vespa-stop-services && /opt/vespa/bin/vespa-remove-index -force && /opt/vespa/bin/vespa-start-services"
    

    Notice the -force, which will not ask for confirmation before deleting the data, also note that indexes is not the only persistent data, configuration state is still retained.

    Example run of a docker container called 'vespa':

    docker exec vespa bash -c "/opt/vespa/bin/vespa-stop-services && /opt/vespa/bin/vespa-remove-index -force && /opt/vespa/bin/vespa-start-services"
    Executing /opt/vespa/libexec/vespa/stop-vespa-base.sh
    config-sentinel was running with pid 7788, sending SIGTERM
    Waiting for exit (up to 15 minutes)
    .. DONE
    configproxy was running with pid 7666, sending SIGTERM
    Waiting for exit (up to 15 minutes)
    . DONE
    [info] You have 23088 kilobytes of data for cluster msmarco
    [info] For cluster msmarco distribution key 0 you have:
    [info] 23084 kilobytes of data in var/db/vespa/search/cluster.msmarco/n0
    [info] removing data:  rm -rf var/db/vespa/search/cluster.msmarco/n0
    [info] removed.
    
    Running /opt/vespa/libexec/vespa/start-vespa-base.sh
    Starting config proxy using tcp/localhost:19070 as config source(s)
    runserver(configproxy) running with pid: 10553
    Waiting for config proxy to start
    config proxy started after 1s (runserver pid 10553)
    runserver(config-sentinel) running with pid: 10679