Python Docker
Dockerfile
FROM python:3
WORKDIR /usr/src/app
COPY requirements.txt ./
RUN pip install --no-cache-dir -r requirements.txt
COPY . .
CMD [ "python", "./your-daemon-or-script.py" ]
or (if you need to use Python 2):
FROM python:2
WORKDIR /usr/src/app
COPY requirements.txt ./
RUN pip install --no-cache-dir -r requirements.txt
COPY . .
CMD [ "python", "./your-daemon-or-script.py" ]
You can then build and run the Docker image:
$ docker build -t my-python-app .
$ docker run -it --rm --name my-running-app my-python-app
Tests
mkdir myapp
vi myapp/helloworld.py
#!/usr/bin/python
print("Hello, World!");
docker run --rm -v $PWD/myapp:/usr/src/myapp -w /usr/src/myapp python:3 python helloworld.py
pip
Upgrade pip
python -m pip install --upgrade pip
pip -V
Config pip
pip config set global.index-url https://pypi.tuna.tsinghua.edu.cn/simple
# https://mirrors.aliyun.com/pypi/simple/
pip install ping3 -i https://pypi.tuna.tsinghua.edu.cn/simple
Conda
conda config --add channels https://mirrors.tuna.tsinghua.edu.cn/anaconda/pkgs/free/
conda config --add channels https://mirrors.tuna.tsinghua.edu.cn/anaconda/cloud/conda-forge
conda config --add channels https://mirrors.tuna.tsinghua.edu.cn/anaconda/cloud/msys2/
conda config --set show_channel_urls yes
conda config --show
Tips
ps -ef | grep python
ps aux | grep python