Using Compose with Finch¶
Containerized applications composed of multiple services are often defined in
Docker Compose
files. Finch
offers a CLI that is compatible to the
docker compose cli, therefore commands that
you have used previously like docker compose up could be translated to finch
compose up.
Building Containers Images with a Compose File¶
A service defined in a compose file can be built with the finch compose
command. To do so, add the
build key, with the value
set as local context to use.
-
In the hello-finch sample application directory, we can create a Compose file. In the file we define the
hello-finchservice and provide a context for the container image build.git clone https://github.com/runfinch/finch.git cd finch/contrib/hello-finch # Add a Compose File to the Directory cat <<EOF > compose.yaml services: hello-finch: image: hello-finch build: . EOFgit clone https://github.com/runfinch/finch.git cd finch/contrib/hello-finch # Add a Compose File to the Directory @" services: hello-finch: image: hello-finch build: . "@ > compose.yamlgit clone https://github.com/runfinch/finch.git cd finch/contrib/hello-finch # Add a Compose File to the Directory cat <<EOF > compose.yaml services: hello-finch: image: hello-finch build: . EOF -
Build the container images using
finch compose build.finch compose buildfinch compose buildsudo finch compose build -
You can verify that the container image has been built successfully using the
finch image listcommand.finch image listfinch image listsudo finch image listThe output should show the container image tagged with the service name.
REPOSITORY TAG IMAGE ID CREATED PLATFORM SIZE BLOB SIZE hello-finch latest 69b2528740fe 49 seconds ago linux/arm64 1.8 MiB 1008.4 KiB
Running Containers with a Compose File¶
1 or more services can be defined in a compose file, and then all services can
be started with the finch compose up command.
-
Leveraging the hello-finch sample application, we can create a Compose file. In the file we define the
hello-finchservice and provide a context for the container image build.git clone https://github.com/runfinch/finch.git cd finch/contrib/hello-finch # Add a Compose File to the Directory cat <<EOF > compose.yaml services: hello-finch: image: hello-finch build: . EOFgit clone https://github.com/runfinch/finch.git cd finch/contrib/hello-finch # Add a Compose File to the Directory @" services: hello-finch: image: hello-finch build: . "@ > compose.yamlgit clone https://github.com/runfinch/finch.git cd finch/contrib/hello-finch # Add a Compose File to the Directory cat <<EOF > compose.yaml services: hello-finch: image: hello-finch build: . EOF -
Next we will run the service with
finch compose up, if the container image does not exist locally, finch will build the container image before starting the service.finch image listfinch image listsudo finch compose upUpon success, the output should look something like the following:
INFO[0018] Creating container hello-finch_hello-finch_1 INFO[0018] Attaching to logs hello-finch_1 | hello-finch_1 | @@@@@@@@@@@@@@@@@@@ hello-finch_1 | @@@@@@@@@@@@ @@@@@@@@@@@ hello-finch_1 | @@@@@@@ @@@@@@@ hello-finch_1 | @@@@@@ @@@@@@ hello-finch_1 | @@@@@@ @@@@@ hello-finch_1 | @@@@@ @@@# @@@@@@@@@ hello-finch_1 | @@@@@ @@ @@@ @@@@@@@@@@ hello-finch_1 | @@@@% @ @@ @@@@@@@@@@@ hello-finch_1 | @@@@ @@@@@@@@ hello-finch_1 | @@@@ @@@@@@@@@@@& hello-finch_1 | @@@@@ &@@@@@@@@@@@ hello-finch_1 | @@@@@ @@@@@@@@ hello-finch_1 | @@@@@ @@@@@( hello-finch_1 | @@@@@@ @@@@@@ hello-finch_1 | @@@@@@@ @@@@@@@ hello-finch_1 | @@@@@@@@@@@@@@@@@@@@@@@@@@ hello-finch_1 | @@@@@@@@@@@@@@@@@@ hello-finch_1 | hello-finch_1 | hello-finch_1 |Hello from Finch! hello-finch_1 | hello-finch_1 |Visit us @ github.com/runfinch hello-finch_1 | INFO[0018] Container "hello-finch_hello-finch_1" exited INFO[0018] All the containers have exited INFO[0018] Stopping containers (forcibly) INFO[0018] Stopping container hello-finch_hello-finch_1
Next Steps¶
In this short section, you learned how to use Compose files with Finch.
- To learn about leveraging Compose files with Finch, see the Finch Compose reference.