Docker `free(): invalid pointer` error with streamlit

Summary

After creating a docker image successfully, a simple docker run command to run streamlit fails with just the following:
free(): invalid pointer. Weirdly, if I interactively enter the container and change the working directory before calling streamlit run, it works and runs fine. However, I am unable to run streamlit run main.py directly from a CMD or ENTRYPOINT.

Steps to reproduce

Code snippet:

FROM python:3.9

#give ARG PORT a default value = production
ARG PORT=8501
ENV PORT=$PORT \
    STREAMLIT_SERVER_PORT=$PORT
EXPOSE $PORT

# Copy source code
COPY poetry.lock pyproject.toml /app /app/
COPY /.streamlit /root/

WORKDIR /app

# Install dependencies
# Create 3.9-python virtualenv 
RUN pip install --upgrade pip \
    && pip install poetry==1.1.6 \
    && poetry config virtualenvs.create false \
    && poetry install --no-dev --no-interaction

ENTRYPOINT ["streamlit", "run", "main.py"]

My pyproject.toml looks like this:

[tool.poetry.dependencies]
python = ">=3.7.1, <3.10"
Bottleneck = "^1.3.2"
numexpr = "^2.7.3"
numpy = "^1.20.3"
pandas = "^1.2.4"
google-cloud-bigquery = {extras = ["bqstorage", "pandas"], version = "^2.18.0"}
google-api-python-client = "^2.7.0"
google-auth-oauthlib = "^0.4.4"
altair = "^4.1.0"
streamlit = "0.81.0"
watchdog = "^2.1.2"
Pillow = "^8.2.0"

[tool.poetry.dev-dependencies]
aquirdturtle-collapsible-headings = "^3.1.0"
black = "^21.5b2"
dask-labextension = "^5.0.2"
ipywidgets = "^7.6.3"
isort = "^5.8.0"
jupyter-dash = "^0.4.0"
jupyterlab = "^3.0.16"
jupyterlab-git = "^0.30.1"
jupyterlab-code-formatter = "^1.4.10"
jupyterlab-widgets = "^1.0.0"
jupyterlab-system-monitor = "^0.8.0"
jupytext = "^1.11.2"
pre-commit = "^2.13.0"
rise = "^5.7.1"
tqdm = "^4.61.0"
watermark = "^2.2.0"
xeus-python = "^0.12.4"

I simply run docker build -t my_app .
and then docker run -t -p 8501:8501 my_app, which gives:

2021-06-16 20:34:51.723 NumExpr defaulting to 4 threads.
free(): invalid pointer
Aborted

In the Dockerfile, if i remove the ENTRYPOINT and then docker exec into the container:

  1. I have to change the directory to another directory (e.g. simple cd ..)
  2. Then running streamlit run app/main.py works fine.
  3. But going back to /app and running streamlit run fails.
  4. This also fails if I use / as my workdir.

Debug info

  • Streamlit version: 0.81.0
  • Python version: 3.9.5
  • Using poetry==1.1.6
  • OS version: Mac M1 Big Sur
  • Browser version: Chrome 91.0.4472.77