Skip to content

Running as non-root user fails with "No module named 'requests'" #162

@bobdoah

Description

@bobdoah

Describe the bug
When running as non-root, the Docker image fails to run with:

Traceback (most recent call last):                                                                                                                                                                       
  File "/cloudflare-ddns.py", line 17, in <module>                                                                                                                                                         
    import requests                                                                                                                                                                                   
ModuleNotFoundError: No module named 'requests' 

This is because the directory where the dependencies are copied, /root/.local/, is not the user's home directory, and is inaccessible.

To Reproduce
Steps to reproduce the behavior:

  1. Using the Kubernetes manifest, add:
template:
   spec:
      securityContext:
         runAsUser: 1000
         runAsGroup: 1000
  1. Pod will fail to run

Expected behavior
The pod should run as non root. Ideally, a USER directive will be used in the Dockerfile, so runAsNonRoot: true can be used in preference to runAsUser and runAsGroup.

Introduced by the change to a multi-stage Docker build: #127

Metadata

Metadata

Assignees

Labels

No labels
No labels

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions