How to run a Docker image under Github CI?

372 views Asked by At

Is there some sort of trick to building and running a Docker image from Github-CI? I've gone through their documentation but I can't find anything that applies to my use case.

Because I want to maintain compatibility with generic Docker, I don't want to use their built-in Docker container stuff. I just want to run the same scripts I have to build and run Docker images on my local Ubuntu 20.04 dev machine.

My .github/workflows/ci.yml looks like:

name: CI
on:
  push:
    branches:
    - master
  pull_request:
    branches:
    - master
jobs:
  build:
    name: Build Docker
    runs-on: ubuntu-20.04
    steps:
      - name: Checking out our code
        uses: actions/checkout@master
      - name: Run Docker
        run: |
          docker --version
          ./build-docker.sh
          ./run-docker.sh
          ./check_results.sh

I'm new to Github's CI, but if I understand their docs correctly, this should spin up an Ubuntu 20.04 VM, checkout my code, and then run my three scripts to build, run and then check the container's output.

My build-docker.sh looks like:

#!/bin/bash
docker build -t myimage -f Dockerfile.ubuntu2104 .

And my run-docker.sh looks like:

docker run -it --name=ubuntu-gnome --rm \
    --tmpfs /run --tmpfs /run/lock --tmpfs /tmp \
    --cap-add SYS_BOOT --cap-add SYS_ADMIN \
    -v /sys/fs/cgroup:/sys/fs/cgroup \
    -v "$(pwd)/testing:/home/default/shared" \
    -p 5901:5901 -p 6901:6901 \
    myimage

This image includes some scripts that test my code in an Ubuntu 21.04 environment. I mount a local ./testing folder as a volume, which these scripts write their logs to so I can confirm their output with my check_results.sh script.

This works perfectly when I run it from my Ubuntu 20.04 localhost. However, when I push it to Github, the ./run-docker.sh line appears to fail or exit without even outputting anything. On my localhost, I see the normal Docker output you get when you launch an image, along with Ubuntu's normal bootup messages. But on Github I get nothing.

Even if I change the script line to ./run-docker.sh || true so it passes, and then add a ls ./testing, it looks like nothing gets written to the shared volume, meaning the Docker image isn't actually being run, or my scripts in the image aren't being run, or they're being prevented from writing to the volume. Either way, I'm not sure how to diagnose the problem, since it's not giving me any output, and Github's CI is black box that doesn't give me many options to debug.

I added the docker --version line to confirm the version, and it looks like Github is running almost the identical Docker version that I'm using on my localhost, so I don't think it's a Docker version issue.

Are there any limitations with the Github CI VM that would break Docker images?

What can I do to get my Docker image to run, or at least figure out what the immediate problem is?

Could the problem potentially be my use of --tmpfs mounting local directories that might not exist in Github's VM?

0

There are 0 answers