how to run pipenv inside a docker container

PIPENV Crontab & Docker: How to Run PIPENV Python Automatically Properly in Cron Jobs with Pipenv – Running Django On a Server

How to run Pipenv in a Docker Container, or using Crontab

When you run pipenv shell, you will notice a link in you console terminal output with a dot (.) symbol.
This symbol is the shell command for “source”.

pipenv cron job source activate
pipenv cron job source activate

If you haven’t installed pipenv here is the setup:

# Install Pipenv on Ubuntu / Debian (Works on Docker)
apt install pipenv -y
pip3 install --upgrade pip
pip3 install --upgrade pipenv
touch Pipfile
export SHELL=/bin/bash
python3 -m pipenv --python 3.8

# CentOS / Red Hat
yum install epel-release
yum install python3 python3-pip
pip3 install pipenv
touch Pipfile
pipenv install

Locate your activate bin file:

find $HOME/.local/share/virtualenvs/ | grep 'activate$'

Now you can use that activate bin inside your cron jobs as follow:

# these two commands are the same
. /home/admin/.local/share/virtualenvs/private-3Qz0_VCC/bin/activate
# or
source /home/admin/.local/share/virtualenvs/private-3Qz0_VCC/bin/activate

This gets your inside your python pipenv shell, where running “python” does it’s magic.

For example, here’s how to run Django
Type “crontab -e” and enter the cron job

source /home/admin/.local/share/virtualenvs/private-3Qz0_VCC/bin/activate && cd /home/user/ && nohup python runserver &

Here are some examples to help you understand

Here’s a fully automated Docker way:

# in any ubuntu image

RUN apt update -y
RUN apt install pipenv -y
RUN pip3 install --upgrade pip
RUN pip3 install --upgrade pipenv
RUN export SHELL=/bin/bash
RUN python3 -m pipenv --python 3.8

If you receive this error:

  File "/usr/lib/python3/dist-packages/pipenv/", line 475, in create_pipfile
    config_parser = ConfigOptionParser(
  File "/usr/lib/python3/dist-packages/pipenv/vendor/pip9/", line 149, in __init__


you can try two things

export SHELL=/bin/bash
pipenv shell
touch pipfile
pipenv shell

Leave a Reply

Your email address will not be published. Required fields are marked *