Learning paths / Containers / Docker Compose

Lab: from Compose to ComputeSphere

Verified lab · 40 min · Module 6, lesson 4 of 545 min left in this module

Module 6 · Docker ComposeLesson 4 of 5

Self-checked for now. Automatic checking arrives with sign-in; until then, tick off each item under Check your work yourself.

Goal: Import a two-service Compose stack and run it on ComputeSphere, with the web app calling the API over the private network.

You need A ComputeSphere account and csph set up, from lesson 5.1.1, Set up; the compose-stack sample from lesson 3.6.2; Docker; and a Docker Hub or GitHub account.

Setting up, and the trial's limit

Lesson 5.1.1 covers signing up, creating the learn project, installing csph and csph auth login.

This lab runs two Flex spherelets. The trial allows two at a time, so delete any other lab service first.

  1. Build and push the web app

    In compose-stack, with <you> as your Docker Hub or GitHub username in lowercase:

    docker build --platform linux/amd64 -t <you>/compose-web:1.0.0 ./app
    docker push <you>/compose-web:1.0.0
    

    ComputeSphere runs linux/amd64 images, so build for that even on an Apple Silicon Mac.

    Never pushed an image?

    Do lesson 3.5.3 first. It covers the token, docker login, and making the image public, which ComputeSphere needs to pull it without credentials.

    Can't push your own image yet?

    If you can't push your own image yet, use quay.io/computesphere/learn-compose-web:1.3.0 and come back to pushing in 3.5.3.

    You should seeA push that ends with a line holding 1.0.0 and a sha256 digest.

  2. Point the deploy file at your image

    Open compose.deploy.yaml and replace <your-registry>/compose-web:1.0.0 with the name you pushed.

    You should seeimage: <you>/compose-web:1.0.0 (or the ghcr.io name) under web.

  3. Import it

    csph import compose -f compose.deploy.yaml --force
    

    --force replaces the computesphere.yaml from lesson 3.6.3, if you made one. Check that API_URL is now a fromService reference to api.

    You should see✓ wrote computesphere.yaml (2 services), and no warnings.

  4. Create an environment with Private Network

    csph regions list
    csph environments create --name compose-lab --region <region> \
      --project <project-id> --private-network=true
    csph environments list --project <project-id>
    

    web reaches api by its private address, which only works with Private Network on, and it must be on when the environment is created.

    You should seecompose-lab in the list, with its ID in the first column.

  5. Apply the manifest

    csph apply -f computesphere.yaml \
      --project <project-id> --environment <compose-lab-id>
    

    With two services, apply returns once both are accepted.

    You should seeApplied 2 resource(s) — status: success, with web and api both created.

  6. Wait for both to be Running

    In the console, open Projects, then learn, then compose-lab. Open web and copy its URL.

    Check yourself

    Why does web's API_URL stop at the service name api in Compose, but get a different address here?

    You should seeweb and api both Running in compose-lab.

  7. Check web can reach api

    curl https://<your-web-url>/healthz
    

    You should see{"status":"ok","api":"reachable"}

Check your work

  • If this doesn't pass

    If apply printed failed, the line under it says why. An image-pull failure usually means the image is private or the name in compose.deploy.yaml doesn't match what you pushed.

  • If this doesn't pass

    If web keeps failing, open its deploy log. An image built on Apple Silicon without --platform linux/amd64 won't start: rebuild, push, and apply again.

  • If this doesn't pass

    api unreachable means the environment has no Private Network. Create a new environment with --private-network=true and apply into it.

Clean up
csph services list --project <project-id>
csph services delete <service-id>      # once for web, once for api
csph environments delete <compose-lab-id>