-
Notifications
You must be signed in to change notification settings - Fork 14
/
pythonDocker.md
72 lines (65 loc) · 1.71 KB
/
pythonDocker.md
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
# 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
```sh
mkdir myapp
vi myapp/helloworld.py
```
```python
#!/usr/bin/python
print("Hello, World!");
```
```sh
docker run --rm -v $PWD/myapp:/usr/src/myapp -w /usr/src/myapp python:3 python helloworld.py
```
## pip
### Upgrade pip
```sh
python -m pip install --upgrade pip
pip -V
```
### Config pip
```sh
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
```sh
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
```sh
ps -ef | grep python
ps aux | grep python
```
## References
- [Python Docker](https://hub.docker.com/_/python?tab=description&page=1&ordering=last_updated)
- [Docker 安装 Python](https://www.runoob.com/docker/docker-install-python.html)
- [解决conda下载速度慢的问题](https://blog.csdn.net/Xiao_Spring/article/details/109130663)