Skip to content

Monitoring a Website

Docker environments are a good fit for small monitoring jobs that don't need a full workflow — checking that a site responds, and alerting a Slack channel when it doesn't. This guide walks through setting one up end to end: an environment, a schedule, and a Command that retries before giving up.

Create the environment

  1. Go to Environments and click Add Environment.

  2. Set Type to Docker and Source to Image.

  3. Set Image to curlimages/curl:latest — a minimal image that ships curl and nothing else, which is all this Command needs.

  4. Save the environment.

Write the schedule

  1. Go to Schedules and click Add Schedule.

  2. Set Environment to the Docker environment created above.

  3. Under Environment Variables, add SLACK_WEBHOOK_URL with the webhook URL for the Slack channel that should receive the alert.

  4. Set Command to a retry loop that posts to Slack only once all attempts have failed:

    bash
    URL="https://example.com"
    MAX_RETRIES=3
    
    for i in $(seq 1 $MAX_RETRIES); do
      echo "Attempt $i/$MAX_RETRIES: checking $URL ..."
      if curl -sf -o /dev/null "$URL"; then
        echo "Success: $URL is reachable"
        exit 0
      fi
      echo "Attempt $i failed"
      sleep 5
    done
    
    echo "All $MAX_RETRIES attempts failed, notifying Slack"
    curl -X POST -H 'Content-type: application/json' \
      --data "{\"text\":\"$URL is not responding after $MAX_RETRIES attempts\"}" \
      "$SLACK_WEBHOOK_URL"
    exit 1

    Exiting non-zero on final failure also marks the run as failed, so Runner's own run history and any Notifications you've enabled reflect the outage too — the Slack post is an additional, faster channel.

  5. Set Schedule to how often the check should run, for example */5 * * * * for every 5 minutes.

  6. Save the schedule and set it to Active.

Adjusting the example

  • Swap curlimages/curl for a python or node image and rewrite the Command in that language — see the examples in Schedules.
  • If the check needs a tool the image doesn't include, install it via the environment's Additional Dockerfile Instructions instead of switching images — see Environments.
  • To alert multiple channels or add email, extend the final curl call or enable the schedule's own Notify on failed runs toggle instead of maintaining the logic in the Command.
Was this page helpful?