Docker Community Forums

Share and learn in the Docker community.

Getting operror-value: source code string cannot contain null bytes with pip

Hey hi folks. First time running docker for a project. That’s what I get when I run docker-compose up --build

Building project-web
Step 1/13 : FROM pypy:3-slim
 ---> bed039c03b04
Step 2/13 : ENV PYTHONUNBUFFERED 1
 ---> Using cache
 ---> 43c8459521d0
Step 3/13 : RUN apt-get update && apt-get install -y --no-install-recommends 		libpq-dev 		gcc 		git 		make 		wget
 ---> Using cache
 ---> 286c0ca2e473
Step 4/13 : RUN mkdir /src
 ---> Using cache
 ---> 9a74252515eb
Step 5/13 : WORKDIR /src
 ---> Using cache
 ---> 28ccf382df5e
Step 6/13 : COPY ./requirements.txt /src/
 ---> Using cache
 ---> 1f8d46e6555d
Step 7/13 : RUN pip install -U pip && pip install -r requirements.txt
 ---> Running in df4629cf294e
debug: OperationError:
debug:  operror-type: ValueError
debug:  operror-value: source code string cannot contain null bytes
ERROR: Service 'project-web' failed to build: The command '/bin/sh -c pip install -U pip && pip install -r requirements.txt' returned a non-zero code: 1

Below is my Dockerfile:

FROM pypy:3-slim
ENV PYTHONUNBUFFERED 1
RUN apt-get update && apt-get install -y --no-install-recommends \
		libpq-dev \
		gcc \
		git \
		make \
		wget
RUN mkdir /src
WORKDIR /src
COPY ./requirements.txt /src/
RUN pip install -U pip && pip install -r requirements.txt
RUN echo "deb http://apt.postgresql.org/pub/repos/apt/ jessie-pgdg main" >> /etc/apt/sources.list && \
    wget --quiet -O - https://www.postgresql.org/media/keys/ACCC4CF8.asc | apt-key add - && \
    apt-get update && apt-get install -y --no-install-recommends \
		libpq-dev \
		postgresql-client \
	&& rm -rf /var/lib/apt/lists/*
COPY ./manage.py /src/
COPY ./gunicorn.conf /src/
# COPY ./.coveragerc /src/
# COPY ./fixtures/default_data.yaml /src/
COPY ./project /src/project/
COPY ./bin/initialize.sh /src/bin/
# COPY ./fixtures/default_data.yaml /src/fixtures/
RUN apt-get purge -y --auto-remove gcc git make wget

I believe the error is with pip for pypy:3-slim because if I add a line like RUN pip --version before install the requirements.txt it’ll break.

Building project-web
Step 1/14 : FROM pypy:3-slim
 ---> bed039c03b04
Step 2/14 : ENV PYTHONUNBUFFERED 1
 ---> Using cache
 ---> 43c8459521d0
Step 3/14 : RUN apt-get update && apt-get install -y --no-install-recommends 		libpq-dev 		gcc 		git 		make 		wget
 ---> Using cache
 ---> 286c0ca2e473
Step 4/14 : RUN mkdir /src
 ---> Using cache
 ---> 9a74252515eb
Step 5/14 : WORKDIR /src
 ---> Using cache
 ---> 28ccf382df5e
Step 6/14 : COPY ./requirements.txt /src/
 ---> Using cache
 ---> 1f8d46e6555d
Step 7/14 : RUN pip --version
 ---> Running in bb90343475b0
debug: OperationError:
debug:  operror-type: ValueError
debug:  operror-value: source code string cannot contain null bytes
ERROR: Service 'project-web' failed to build: The command '/bin/sh -c pip --version' returned a non-zero code: 1

I only got everything working when I changed it from pypy:3-slim to pypy:3.6-slim or pypy:3.
Here are the versions of what I’m using:

docker-compose version 1.23.2, build 1110ad01
Docker version 18.09.2, build 6247962

➜ uname -a
Darwin MacBook-Pro-2.local 18.2.0 Darwin Kernel Version 18.2.0: Thu Dec 20 20:46:53 PST 2018; root:xnu-4903.241.1~1/RELEASE_X86_64 x86_64

Any clue about what would cause this problem?