Closed
Description
Hi,
I'm trying to run a script inside a container.
I don't know the UID the container runs as at build time and I don't want to initialize the container as root, so I can't workaround by creating the user at runtime.
This means that at runtime the UID the script is running as does not have an entry in /etc/passwd
.
This is however expected at least in the current master at the time of writing, not sure if there are other places where this is expected in the code:
aiomysql/aiomysql/connection.py
Line 45 in 0a8af23
Currently when trying to import aiomysql
the following exception is raised:
Traceback (most recent call last):
File "demo.py", line 2, in <module>
import aiomysql
File "/usr/local/lib/python3.7/site-packages/aiomysql/__init__.py", line 32, in <module>
from .connection import Connection, connect
File "/usr/local/lib/python3.7/site-packages/aiomysql/connection.py", line 45, in <module>
DEFAULT_USER = getpass.getuser()
File "/usr/local/lib/python3.7/getpass.py", line 169, in getuser
return pwd.getpwuid(os.getuid())[0]
KeyError: 'getpwuid(): uid not found: 12345'
To reproduce:
Dockerfile
FROM python:3.7-slim-buster
RUN pip3 install aiomysql
COPY demo.py /app/
WORKDIR /app
ENTRYPOINT ["/usr/bin/env", "python3", "demo.py"]
demo.py
print("Hello World from container")
import aiomysql
- build container
DOCKER_BUILDKIT=1 docker build -t test-py .
- run container as uid 12345
docker run --rm -it --user 12345 test-py
- see KeyError