Is there the better way to wait to start docker-up?

Hi Gitpod folks! :slightly_smiling_face:

I’d like to launch the containerized application automatically after creating a workspace.
For that, I’m writing .gitpod.yml like this:

# List the ports you want to expose and what to do when they are served. See
  - port: 1313
    onOpen: open-browser

# List the start up tasks. You can start them in parallel in multiple terminals. See
  - command: |
      while [[ $(docker info > /dev/null; echo $?) != 0 ]]; do
          sleep 1
      docker run -p 1313:1313 <application-container>
  - command: sudo docker-up

This config opens two terminals. One uses the docker command to launch the containerized application and the second one launches the docker-up.

I need to wait until the docker-up launched. If not, docker run in the first command failed because the docker socket is not ready before the docker-up launch. The above config works as expected but I feel a bit hacky. Does anyone know the better solution?

Thank you.

1 Like

Currently, Kubernetes containers don’t have systemd due to bandwidth and storage reasons.

1 Like

Hi @shuuji3, welcome to the Gitpod community! :partying_face:

Indeed, having to wait on docker-up with a while loop seems a bit awkward…

However, maybe the solution is simply to switch the order of the Terminals? (I.e. open the one with sudo docker-up first, then the one with docker run?) While all Terminals start & run in parallel to each other, in practice I’ve noticed that running prerequisites first often “just works” out-of-the-box.

For example, we also open two Terminals for Docker in Gitpod’s workspace-images repository, and this seems to always work fine without the extra waiting logic:

I added sleep 5 in a parallel terminal. Without it I would get an error related to sudo docker-up not running yet.


Thanks, I guess the sleep trick also works. But why run sudo docker-up after running the commands that need it?

I thought all these terminal open in parallel, so it’s not “after”.
The reason I ordered the terminals this way, is that the “active” terminal where all the action happen, and where the user will be able to add commands is the first one.
Before, when I had the sudo docker-up first - it was confusing, because when the workspace was ready, the user cannot run commands in that terminal, and has to switch to a different terminal.

Had the same concern and not a fan of fixed sleep time since too uncertain. And sometimes it didn’t work for me, with sudo docker-up in before task and the docker command waiting for 10s.

Thanks for the idea of checking docker info, that’s exactly what I needed!

My latest version looks like this:

Of course you can use the docker daemon in a command instead of before as needed, I chose this way to be able to do one-time-init. And it’s not compatible with prebuild unless you kill the daemon process to stop the before task.

1 Like

Just another solution: use while [ ! -S /var/run/docker.sock ]; do sleep 1; done to wait until docker is up.

1 Like