Linux Docker部署python及配置nginx

279 阅读2分钟
1: git clone https://xxxx 代码仓地址
2: 安装docker 
# 国外
curl -fsSL https://get.docker.com | bash -s docker --mirror Aliyun
#or 国内
curl -sSL https://get.daocloud.io/docker | sh    

3: #cd到git拉取项目的文件下,创建docker 容器(xxx:代表你容器的名字)   

docker build -t xxx .

   #运行

docker run --rm -it --net=host xxx  #运行停止后删除
docker run -it --net=host xxx  #运行停止后不删除
在浏览器中输入:IP:端口号验证,没问题 停止运行(ctrl+c
    # 启动容器:
    docker ps -a  #查看所有容器
    docker start  CONTAINER ID #(容器ID)                        

4: docker 安装及配置nginx反向代理(xxxx:代表你nginx容器的名字)

4.1 # 创建nginx挂载目录:

mkdir -p /root/nginx/www /root/nginx/logs /root/nginx/conf /root/nginx/html /root/nginx/cret

cert:存放SSL证书

启动nginx容器,用于copy一些文件放在步骤4.1的目录下

docker run --name nginx -p 80:80 -d nginx

将nginx容器下文件,copy到步骤4.1的目录下

docker cp nginx:/etc/nginx/conf.d /root/nginx/conf/

docker cp nginx:/etc/nginx/nginx.conf /root/nginx/conf/nginx.conf

docker cp nginx:/usr/share/nginx/html/index.html /root/nginx/html/index.html

删除nginx容器

docker stop nginx

docker rm -f nginx

4.2 #根据业务修改宿主机目录中的nginx.conf文件、并并删除容器、重启容器

            # 配置项https

            # 配置http转发

4.3# 启动容器并挂载目录

docker run \

-p 443:443 -p 80:80 \

--name xxxx \

-v /root/nginx/conf/nginx.conf:/etc/nginx/nginx.conf \

-v /root/nginx/conf/conf.d:/etc/nginx/conf.d \

-v /root/nginx/logs:/var/log/nginx \

-v /root/nginx/cert:/etc/nginx/cert \

-v /root/nginx/ssl:/etc/nginx/ssl/ \

-v /root/nginx/html:/usr/share/nginx/html \

--privileged=true -d --restart=always nginx:latest

5.#注意事项

defaul.conf文件中,出现的绝对路径都是容器内的路径,而不是宿主机的,比如说配置ssl时:

ssl_certificate  /etc/nginx/cert/telami.cn.pem; #此处不是宿主机目录,而是容器内的路径

ssl_certificate_key /etc/nginx/cert/telami.cn.key; #此处不是宿主机目录,而是容器内的路径

6.#查找安装路径 nginx

   whereis nginx

7.#查找nginx配置项所在位置

   sudo find / -name nginx.conf

8.#不重启docker更新nginx配置文件

#查看容器

docker ps -a

测试nginx配置是否正确

docker exec 容器id nginx -t

重新加载nginx配置

docker exec