question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

pip doesn't work in docker containers

See original GitHub issue

Describe the bug The runner changes HOME variable for job containers, but the home directory remains owned by someone else, and /etc/passwd does not reflect the change. This causes all kinds of side effects.

I had another case. I tried to run sshd in a container, and it didn’t work because home directory in /etc/passwd was still /root, so I had to:

apk add gawk
awk -i inplace -F: '
    $1 == "root" {print $1 ":" $2 ":" $3 ":" $4 ":" $5 ":/github/home:" $7}
    $1 != "root" {print $0}
' /etc/passwd

Okay, making containers communicate over ssh was probably a silly idea. This was my first time configuring a workflow. But still, changing HOME breaks some software.

To Reproduce Steps to reproduce the behavior:

.github/workflows/django.yml:

...
name: Django workflow

on:
  push:
    branches: [ master ]

jobs:
  build:
    runs-on: ubuntu-latest
    container: python:3.5-alpine3.12
    steps:
      - run: apk add expect && unbuffer sh -euxc '
          whoami
          && set
          && ls -Al `dirname "$HOME"`
          && cat /etc/passwd
          && pip cache dir
          && exit 1
          '

Output:

+ whoami
root
+ set
HOME='/github/home'
+ ls -Al /github
total 8
drwxr-xr-x    2 1001     116           4096 Aug  9 13:14 home
drwxr-xr-x    2 1001     116           4096 Aug  9 13:14 workflow
+ cat /etc/passwd
root:x:0:0:root:/root:/bin/ash
+ pip cache dir
WARNING: The directory '/github/home/.cache/pip' or its parent directory is not owned or is not writable by the current user. The cache has been disabled. Check the permissions and owner of that directory. If executing pip with sudo, you may want sudo's -H flag.
ERROR: pip cache commands can not function since cache is disabled.

Expected behavior pip finishes successfully. Ideally, HOME shouldn’t be changed. At least provide some recommendations, or explain your reasoning.

Runner Version and Platform

The one running on GitHub.

Issue Analytics

  • State:open
  • Created 3 years ago
  • Comments:5

github_iconTop GitHub Comments

1reaction
Birdi7commented, Mar 17, 2022

Hello! Any updates on this issue? I didn’t workout to configure pip dependency caching because of this. I have a container with volume for pip cache directory, and it is saved in GH actions cache because of the following error

WARNING: The directory ‘/github/home/.cache/pip’ or its parent directory is not owned or is not writable by the current user. The cache has been disabled. Check the permissions and owner of that directory. If executing pip with sudo, you should use sudo’s -H flag.

1reaction
x-yuricommented, Feb 28, 2022

@rdisipio I guess it needs chown after all:

apk add gawk
awk -i inplace -F: '
    $1 == "root" {print $1 ":" $2 ":" $3 ":" $4 ":" $5 ":/github/home:" $7}
    $1 != "root" {print $0}
' /etc/passwd
chown -R root: ~
Read more comments on GitHub >

github_iconTop Results From Across the Web

Can't install pip packages inside a docker container with ...
However pip works fine to install things outside of the docker container, and worked fine even with that exact package ( blinker==1.3 )...
Read more >
Issue with installing pip packages inside a docker ...
I have setup docker on my fresh ubuntu 16.04.02 setup. successfully run the “docker run hello-world” and “ubuntu bash”.
Read more >
I can't run pip for the docker build
Hello, I try to run my dockerfile on a RaspberryPi 4 with raspian-buster and I get this error: Sending build context to Docker…...
Read more >
pip install not working in docker · Issue #4453
When code is executed, even after pip install has been run, the code gives an error due to the installed module not being...
Read more >
Installing Python Packages In Your Docker Container
However, because pip can only install Python packages, you may find yourself also having to use your package manager (i.e., apt-get install -y...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found