Run code in created Docker image container through github actions

I have an R package and I am trying to use Github-actions to first build a docker image then use this image to run R CMD Check on the package and, if this succeeds, push this image to dockerhub.

My current approach to the .yaml file is:

  1. Checkout the repository
  2. Get R package version from DESCRIPTION file for docker tag
  3. Set up the docker build
  4. Build the image
  5. Run R CMD check
  6. Log in to dockerhub
  7. Push to dockerhub

My approach is working with the exception of running the check on the created docker image. In fact I can’t seem to access the image at all in the github actions workflow. Essentially, I want to run

- name: Check
        run: rcmdcheck::rcmdcheck(args = "--no-manual", error_on = "error")
        shell: Rscript {0}

on the built docker image. I have tried running commands like

- name: Check running containers
        run: docker ps

thinking that if I can get a container ID for the created docker image I can run a R-CMD-CHECK in it but no containers are returned!

This is my current .yaml file which is running fine but excludes the important Run R CMD check step:


name: R GitHub Actions

      - main
      - master
      - dev-am
      - main
      - master

    name: R-CMD-check
    runs-on: ubuntu-latest
      GITHUB_PAT: ${{ secrets.GITHUB_TOKEN }}
      - uses: actions/checkout@v2
      - name: Setup R
        uses: r-lib/actions/setup-r@v1
          install-r: false
      - name: Get R package version
        run: |
          version=$(grep Version DESCRIPTION | grep -o "[0-9.]\+")
          echo "packageVersion=${version}" >> $GITHUB_ENV
        shell: bash {0}    
      - name: Set up Docker Buildx
        uses: docker/setup-buildx-action@v1

      - name: Build service
        uses: docker/build-push-action@v2
          load: true
          tags: |
            almurphy/scfdev:${{ env.packageVersion }}

      - name: Login to DockerHub
        uses: docker/login-action@v1
          username: ${{ secrets.DOCKER_USERNAME }}
          password: ${{ secrets.DOCKER_TOKEN }}

      - name: push service
        run: |
          docker push almurphy/scfdev:${{ env.packageVersion }}
          docker push almurphy/scfdev:latest

Note - This is a similar post, covering the same topic as one I have on the rstudio community: Github-Actions: Build Docker Image, run R CMD Check, push to Dockerhub - Package development - RStudio Community . My apologies for any cross-pollination.

I don’t see anything in your workflow that would start a Docker container, so it’s no surprise you can’t see a running one. You can start one with docker run like you would do locally. Depending on the setup of the container image you might be able to pass your check command right to the run command, or use --detach and then docker exec.