Container's python environment not reproduced

Hi there. I am trying to create a test environment for a package that relies on a very specific C library which is wrapped by another python library. To ensure reproducibility I have created a docker image which downloads and installs all the required dependencies and sets up a python environment with all these pre-installed. It’s a pretty simple docker image, as shown below:

FROM python:3.8-slim-buster

# Install wget and C compilation tools
RUN apt-get update
RUN apt-get install -y wget build-essential

# Install Nauty
WORKDIR /usr/src
RUN wget -O nauty.tar.gz http://pallini.di.uniroma1.it/nauty27r1.tar.gz \
 && tar xvzf nauty.tar.gz \
 && rm nauty.tar.gz \
 && mv nauty27r1 nauty \
 && cd nauty \
 # N.B. -fPIC compile flag needed to avoid compiler error when installing pynauty
 && CC="gcc -fPIC" ./configure \
 && make

# Install PyNauty
WORKDIR /usr/src
RUN wget -O pynauty.tar.gz https://github.com/sammorley-short/pynauty/archive/v1.0.tar.gz \
 && tar xvzf pynauty.tar.gz  \
 && rm pynauty.tar.gz \
 && mv pynauty-1.0 pynauty \
 && cd pynauty \
 && mv ../nauty nauty \
 && make pynauty \
 && make tests \
 && make user-ins

The issue I am having is that if I specify this container in a workflow job, then although the container is pulled and seemingly boots up fine, I then don’t have access to the pre-installed python package, and have to re-install it, as shown in the “Install PyNauty” step below.

name: Python package

on: [push]

jobs:
  build:
    runs-on: ubuntu-latest
    strategy:
      fail-fast: false
      matrix:
        python-version: [3.7, 3.8]

    container: 
      image: sammorleyshort/pynauty:py${{ matrix.python-version }}-slim
    steps:
    - name: Install PyNauty
      run: |
        cd /usr/src/pynauty
        make pynauty
        make user-ins
    - uses: actions/checkout@v2
    - name: Install dependencies
      run: |
        pip install -r requirements.txt
        pip install -e .
        which python
        python -V
        which pip
        pip list
    - name: Lint with flake8
      run: |
        # stop the build if there are Python syntax errors or undefined names
        flake8 . --count --select=E9,F63,F7,F82 --show-source --statistics
        # exit-zero treats all errors as warnings. The GitHub editor is 127 chars wide
        flake8 . --count --exit-zero --max-complexity=10 --max-line-length=127 --statistics
    - name: Test with pytest
      run: |
        pytest

Frustratingly, this is at odds with the situation when I boot up the image locally, in which case I do have the desired python package pre-installed. So my question is: why isn’t the python environment of the loaded container image the same as that which I get when running the image locally? What is GitHub doing differently when loading this image?

GitHub passes specific options to Docker when starting a job container, which probably aren’t the same when you start the container locally. For example, I’m pretty sure the runner overrides the WORKDIR settings from your Dockerfile. It’d take a closer look at a workflow log to be sure, but that’s the first thing I’d check.