Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to launch a host app using Docker Compose

When running a Docker Compose project, it would be nice to be able to open an app with certain parameters on the host operating system (on which docker-compose up is being invoked). This would be legitimately useful when running web apps. For example, I would love to have Docker Compose automatically open a browser on the host with location of http://localhost:8080, when I run docker-compose run, rather than manually opening a browser and entering the http://localhost:8080. Just the way we see in Minikube (e.g when running minikube service web-deployment).
I am aware there are parameters to use in docker-compose.yml to pass commands to run in containers, like command and entrypoint, but I don't know if that is possible for applications on the host OS.

like image 652
djnotes Avatar asked Apr 11 '26 00:04

djnotes


1 Answers

Compose can do a pretty limited set of things. It can build Docker images, without any ordering constraints, and it can start (presumably long-running) Docker containers, with very limited ordering constraints. It can create a couple of associated Docker objects like networks and named volumes. That's literally all it can do, though; it cannot do larger-scale orchestration task ("run this migration container to completion, then run this application") or launch non-Docker tasks.

You might use some host-based tool to manage this instead. Even a shell script would be enough; possibly something like

#!/bin/sh

# start the container stack
# (assumes the caller has permission to do this)
docker-compose up -d

# wait for the service to be ready
while ! curl --fail --silent --head http://localhost:8080; do
  sleep 1
done

# open the browser window
open http://localhost:8080
like image 200
David Maze Avatar answered Apr 12 '26 15:04

David Maze