python整慎、php脏款、nodejs docker部署(20210308在用)
python(fastapi + uvicorn)docker 部署時run命令
docker run -d \
--name mqsub \
--restart=always \
--network php-net \
-p 8000:80 \
-v /root/mqsub:/app \
-e KEEP_ALIVE="20" \
-e GRACEFUL_TIMEOUT="20" \
-e TIMEOUT="20" \
mqsub /start-reload.sh
用于啟動bash文件具體代碼:start-reload.sh
# /start-reload.sh
#! /usr/bin/env sh
set -e
if [ -f /app/app/main.py ]; then
DEFAULT_MODULE_NAME=app.main
elif [ -f /app/main.py ]; then
DEFAULT_MODULE_NAME=main
fi
MODULE_NAME=${MODULE_NAME:-$DEFAULT_MODULE_NAME}
VARIABLE_NAME=${VARIABLE_NAME:-app}
export APP_MODULE=${APP_MODULE:-"$MODULE_NAME:$VARIABLE_NAME"}
HOST=${HOST:-0.0.0.0}
PORT=${PORT:-80}
LOG_LEVEL=${LOG_LEVEL:-info}
# If there's a prestart.sh script in the /app directory or other path specified, run it before starting
PRE_START_PATH=${PRE_START_PATH:-/app/prestart.sh}
echo "Checking for script in $PRE_START_PATH"
if [ -f $PRE_START_PATH ] ; then
echo "Running script $PRE_START_PATH"
. "$PRE_START_PATH"
else
echo "There is no script $PRE_START_PATH"
fi
# Start Uvicorn with live reload
exec uvicorn --reload --host $HOST --port $PORT --log-level $LOG_LEVEL "$APP_MODULE"
python(uwsgi)docker 部署時run命令
docker run -d \
--name mqsub \
--restart=always \
--network php-net \
-p 8000:8000 \
-v /root/mqsub:/home \
mqsub \
/bin/bash /home/entry-point.sh
nodejs docker 部署時run命令
docker run -d \
--restart=always \
-v /root/xy.api:/app \
--network php-net \
-p 3000:3000 \
--name xyys.nodejs \ #鏡像名
xyys.nodejs \ #容器名
node /app/app.js #運行命令
php docker 部署時run命令
docker run -d \
--restart=always \
--name php-web \
--network php-net \
-p 9001:9000 \
-v /www/nginx/apps:/usr/share/nginx/html \
php:5.6-fpm
清華pypi 鏡像速度最快(pip install)
pypi 鏡像每 5 分鐘同步一次。(https://mirrors.tuna.tsinghua.edu.cn/help/pypi/)
臨時使用
pip install -i https://pypi.tuna.tsinghua.edu.cn/simple some-package
設為默認
升級 pip 到最新的版本 (>=10.0.0) 后進行配置:
pip install pip -U
pip config set global.index-url https://pypi.tuna.tsinghua.edu.cn/simple
如果您到 pip 默認源的網(wǎng)絡連接較差裤园,臨時使用本鏡像站來升級 pip:
pip install -i https://pypi.tuna.tsinghua.edu.cn/simple pip -U
docker鏡像image拉取速度過慢 - 倉庫源:中科大速度最快(docker pull)
創(chuàng)建撤师、修改 /etc/docker/daemon.json
vim /etc/docker/daemon.json # 編輯daemon.json
{
"registry-mirrors": ["http://docker.mirrors.ustc.edu.cn"]
}
systemctl restart docker # 重啟docker服務
國內(nèi)主要鏡像
Docker中國區(qū)官方鏡像| https://registry.docker-cn.com
網(wǎng)易| http://hub-mirror.c.163.com
ustc | https://docker.mirrors.ustc.edu.cn
中國科技大學 | https://docker.mirrors.ustc.edu.cn
阿里云 | https://cr.console.aliyun.com
fastapi uvicorn 部署Dockerfile(20210308在用)
#FROM centos/python-36-centos7
FROM tiangolo/uvicorn-gunicorn-fastapi:python3.7
MAINTAINER sam
USER root
WORKDIR /app
# 下載pip包
RUN python -m pip install --upgrade pip -i https://pypi.tuna.tsinghua.edu.cn/simple
RUN pip install requests -i https://pypi.tuna.tsinghua.edu.cn/simple
RUN pip install wheel -i https://pypi.tuna.tsinghua.edu.cn/simple
RUN pip install pycrypto -i https://pypi.tuna.tsinghua.edu.cn/simple
RUN pip install mq_http_sdk -i https://pypi.tuna.tsinghua.edu.cn/simple
RUN pip install aliyunsdkcore -i https://pypi.tuna.tsinghua.edu.cn/simple
RUN pip install -i https://pypi.tuna.tsinghua.edu.cn/simple aliyun-python-sdk-iot
RUN pip install -i https://pypi.tuna.tsinghua.edu.cn/simple fastapi
RUN pip install -i https://pypi.tuna.tsinghua.edu.cn/simple pydantic
RUN pip install -i https://pypi.tuna.tsinghua.edu.cn/simple uvicorn
#COPY requirements.txt /home/requirements.txt
# 使用淘寶的npm鏡像
#RUN pip install -i https://pypi.tuna.tsinghua.edu.cn/simple --trusted-host pypi.tuna.tsinghua.edu.cn
#RUN pip install -r requirements.txt
#ENTRYPOINT [ "/bin/bash", "/home/entry-point.sh"]
#ENTRYPOINT uwsgi --ini /home/hello.ini
#CMD ["uwsgi","--ini", "/home/hello.ini"] #啟動uwsgi
fastapi uvicorn 部署Dockerfile(參考)
FROM python:3.7
RUN pip install fastapi uvicorn
EXPOSE 80
COPY ./app /app
CMD ["uvicorn", "app.main:app", "--host", "0.0.0.0", "--port", "8080"]
清華pypi 鏡像速度最快(pip install)
代碼塊
五級標題
- 列表第一項
- 列表第二項
- 有序列表第一項
- 有序列表第二項
引用段落
斜體
粗體
代碼塊