Skip to content
SHC Docs

A second service

This page adds a second service, api, and with it the first question two services raise: which one does the hostname reach? An app has one front door, and x-shc-primary names the service behind it.

api is traefik/whoami, a small server that answers every request with what it received. Add it after web.

~/learn/guestbook/compose.yaml
services:
web:
image: nginx:1.27-alpine
expose:
- "80"
volumes:
- ./site:/usr/share/nginx/html:ro
api:
image: traefik/whoami:v1.10
command: ["--port", "8080", "--name", "guestbook-api"]
expose:
- "8080"
home01
$ shc update guestbook
...

The services of a deployment reach each other by name. Ask api from inside web: shc exec runs a command in a service’s container.

home01
$ shc exec -s guestbook -S web -- wget -q -O - http://api:8080/hello
Name: guestbook-api
...
GET /hello HTTP/1.1
Host: api:8080
...

The hostname still reaches web. With no service marked, the front door is the first service the file lists, so moving api to the top would move the hostname with it. x-shc-primary: true makes the choice part of the file instead of its order. Mark api.

~/learn/guestbook/compose.yaml
services:
web:
image: nginx:1.27-alpine
expose:
- "80"
volumes:
- ./site:/usr/share/nginx/html:ro
api:
image: traefik/whoami:v1.10
command: ["--port", "8080", "--name", "guestbook-api"]
expose:
- "8080"
x-shc-primary: true
home01
$ shc update guestbook
...
home01
$ curl -sk --resolve guestbook.learn.test:443:127.0.0.1 https://guestbook.learn.test/
Name: guestbook-api
...

The hostname now opens the API. Move the mark to web, where the front door belongs.

~/learn/guestbook/compose.yaml
services:
web:
image: nginx:1.27-alpine
expose:
- "80"
volumes:
- ./site:/usr/share/nginx/html:ro
x-shc-primary: true
api:
image: traefik/whoami:v1.10
command: ["--port", "8080", "--name", "guestbook-api"]
expose:
- "8080"
home01
$ shc update guestbook
...
home01
$ curl -sk --resolve guestbook.learn.test:443:127.0.0.1 https://guestbook.learn.test/
<!doctype html>
<title>guestbook</title>
<p>Sign the guestbook.</p>

x-shc-* keys are SHC’s own: SHC reads them, and compose ignores them. Each one the next pages add is listed, with what it does, in What SHC does to your compose file.

Next: A path under the hostname.