supervisor
supervisor进入容器后还需要配置
supervisor的配置文件
脚本文件
gunicorn.conf的配置文件
# 指定基于的基础镜像
FROM ubuntu:18.04
# 维护信息
MAINTAINER wan** <wan@.ai>
# 更改源
# RUN echo "deb http://archive.ubuntu.com/ubuntu precise main universe" > #/etc/apt/sources.list
# 修改编码
RUN echo export LANGUAGE=en_US.UTF-8 >> /etc/profile
RUN echo export LC_ALL=C.UTF-8 >> /etc/profile
RUN echo export LANG=C.UTF-8 >> /etc/profile
RUN echo export FLASK_APP="/root/projectName/manage.py" >> /etc/profile
RUN echo source /etc/profile >> ~/.bashrc
# 更新 apt-get
RUN apt-get update
RUN apt-get upgrade -y
RUN apt-get install --assume-yes apt-utils
# 安装vim
RUN apt-get install vim -y
# 安装python2.7 和 pip
RUN apt-get install python2.7 -y && apt-get install python-pip -y
# 安装python3.7(兼容性更好) 和 pip3
RUN apt-get install python3.7 -y && apt-get install
python3-pip -y
# 默认的pip配置需要做一下修改,修改完pip下载源,下载项目依赖的时候会非常快,我这里用的阿里源,以下是永久修改下载源方式,下面也有临时下载的方式
# 我们到 指定的目录下
WORKDIR /root/.pip/
# 把我们的pip.conf 拷贝到这里
# ADD 源目录 目标目录
# 源目录: 是相当于 Dockerfile所在的文件
# 目标目录: 镜像目录
# COPY ./pip.conf ./
# 这个pip.conf文件里的内容,下面两行而已(去掉注释)。
# [global]
# index-url = https://mirrors.aliyun.com/pypi/simple/
ADD ./pip.conf ./
# 又回到了 根目录(回不回来都行)
WORKDIR /root
# 安装并配置supervisor
RUN pip install supervisor
RUN echo_supervisord_conf > supervisord.conf这个安装成功过的dockerfile。 不用的原因是不太稳定
RUN echo [include] >> supervisord.conf
RUN echo files = /etc/supervisor/*.conf >> supervisord.conf
RUN cp supervisord.conf /etc
RUN mkdir /etc/supervisor
WORKDIR /etc/supervisor
# 这里创建supervisor的配置文件
RUN touch project1.conf
# 这里创建supervisor 要执行的脚本文件*.sh
RUN mkdir script
WORKDIR script
RUN touch project1.sh
# 给supervisor执行权限,不然无法启动supervisor
RUN chmod 777 project1.sh
# 又回到了 根目录(回不回来都行)
WORKDIR /root
# 安装virtualenv
RUN pip3 install virtualenv
RUN pip3 install virtualenvwrapper
RUN mkdir $HOME/.virtualenvs
# 4.2、打开~/.bashrc文件,并添加如下:
RUN echo export WORKON_HOME=$HOME/.virtualenvs >> ~/.bashrc
RUN echo source /usr/local/bin/virtualenvwrapper.sh >> ~/.bashrc
# 这里有可能报错,virtualenvwrapper.sh不一定在这个路径下,但大概路会在这个路径下。我用的ubuntu18.4是在这
# 进入容器先执行以下两个命令,dockerfile里没办法执行source
#RUN source /usr/local/bin/virtualenvwrapper.sh
#RUN source ~/.bashrc
# 清华:https://pypi.tuna.tsinghua.edu.cn/simple
# 中国科技大学 https://pypi.mirrors.ustc.edu.cn/simple/
# 华中理工大学:http://pypi.hustunique.com/
# 山东理工大学:http://pypi.sdutlinux.org/
# 豆瓣:http://pypi.douban.com/simple/
# 这里说下临时下载源的方法,我已经不用了,因为之后进入容器中安装点什么东西还要重新制定,很麻烦。
# pip3 install PyQt5==5.11.3 -i https://pypi.douban.com/simple/
# 安装一些程序需要的依赖
RUN pip3 install flask
RUN pip3 install gunicorn
RUN pip3 install flask_cors
RUN pip3 install flask_wtf
RUN pip3 install nameko
CMD ["/bin/bash", "/start.sh"]
创建镜像
docker build -t changyu12:1.0 .
运行镜像容器
docker run -itd --network=host --privileged=true -v /home/changyu/mainProject/development:/usr/src/app --name changyu d04cc27df4b1 /bin/bash
入容器
docker exec -it 容器ID /bin/bash
删除所有镜像(慎用)
docker rmi -f $(docker images -qa)
停止并删除所有容器(谨慎)
docker stop $(docker ps -q) & docker rm $(docker ps -aq)
和同事沟通后发现很多其实在容器里不需要安装所以出现下面的精装版本
指定基于的基础镜像
FROM ubuntu:18.04
RUN echo export LANGUAGE=en_US.UTF-8 >> /etc/profile
RUN echo export LANG=en_US.UTF-8>> /etc/profile
RUN echo export LC_ALL=C.UTF-8 >> /etc/profile
RUN echo export LANG=C.UTF-8 >> /etc/profile
RUN echo export FLASK_APP="/usr/src/app/manage.py" >> /etc/profile
RUN echo source /etc/profile >> ~/.bashrc
RUN apt-get update
RUN apt-get upgrade -y
RUN apt-get install sudo
RUN apt-get install vim -y
# ubuntu18.04 里面有python3.6.9版本,所以python也不需要安装
#RUN apt-get install python3.7 -y && apt-get install python3-pip -y
#RUN apt-get install python2.7 -y && apt-get install python-pip -y
# 默认的pip配置需要做一下修改
# 我们到 指定的目录下
WORKDIR /root/.pip/
# 把我们的pip.conf 拷贝到这里
# ADD 源目录 目标目录
# 源目录: 是相当于 Dockerfile所在的文件
# 目标目录: 镜像目录
# COPY ./pip.conf ./
ADD ./pip.conf ./
WORKDIR /usr/src/app
COPY requirements.txt ./
# 又回到了 根目录(回不回来都行)
RUN pip3 install -r requirements.txt
COPY . .
CMD ["/bin/bash", "/start.sh"]
build python alpine version image
# 指定基于的基础镜像
FROM python:3.7-alpine
RUN echo export LANGUAGE=en_US.UTF-8 >> /etc/profile
RUN echo export LANG=en_US.UTF-8>> /etc/profile
RUN echo export LC_ALL=C.UTF-8 >> /etc/profile
RUN echo export LANG=C.UTF-8 >> /etc/profile
RUN echo export FLASK_APP="/usr/src/app/manage.py" >> /etc/profile
RUN echo source /etc/profile >> ~/.bashrc
# 更改apk下载源
RUN sed -i 's/dl-cdn.alpinelinux.org/mirrors.aliyun.com/g' /etc/apk/repositories
RUN apk update
RUN apk upgrade
# mariadb-dev build-base mysql的依赖
RUN apk add --no-cache g++ mariadb-dev build-base
RUN apk add --no-cache alpine-sdk gcc musl-dev python3-dev libffi-dev openssl-dev cargo jpeg-dev zlib-dev ffmpeg
#RUN apt-get --assume-yes update
#RUN apt-get --assume-yes upgrade -y
#RUN apt-get install sudo
#RUN apt-get install vim -y
#RUN apt-get install python3.7 -y && apt-get install python3-pip -y
#RUN apt-get install python3-pip -y
#RUN apt-get install python2.7 -y && apt-get install python-pip -y
# 默认的pip配置需要做一下修改
# 我们到 指定的目录下
WORKDIR /root/.pip/
# 把我们的pip.conf 拷贝到这里
# ADD 源目录 目标目录
# 源目录: 是相当于 Dockerfile所在的文件
# 目标目录: 镜像目录
# COPY ./pip.conf ./
ADD ./pip.conf ./
WORKDIR /usr/src/app
COPY requirements.txt ./
# 又回到了 根目录(回不回来都行)
RUN pip install -r requirements.txt -i https://pypi.douban.com/simple/ --trusted-host pypi.douban.com
COPY . .
CMD ["/bin/bash", "source /etc/profile"]这个安装成功过的dockerfile。 不用的原因是不太稳定
这个安装成功过的dockerfile。 不用的原因是不太稳定
遇到的问题,加粗部分。
WARNING: Discarding https://mirrors.aliyun.com/pypi/packages/d4/85/38715448253404186029c575d559879912eb8a1c5d16ad9f25d35f7c4f4c/cryptography-3.3.2.tar.gz#sha256=5a60d3780149e13b7a6ff7ad6526b38846354d11a15e21068e57073e29e19bed (from https://mirrors.aliyun.com/pypi/simple/cryptography/) (requires-python:>=2.7,!=3.0.,!=3.1.,!=3.2.,!=3.3.,!=3.4.,!=3.5.). Command errored out with exit status 1: /usr/local/bin/python /usr/local/lib/python3.8/site-packages/pip install --ignore-installed --no-user --prefix /tmp/pip-build-env-o_dd4j3p/overlay --no-warn-script-location --no-binary :none: --only-binary :none: -i https://mirrors.aliyun.com/pypi/simple/ – ‘setuptools>=40.6.0’ wheel ‘cffi>=1.12; platform_python_implementation != ‘"’"‘PyPy’"’"’’ Check the logs for full command output.
ERROR: Could not find a version that satisfies the requirement cryptography3.3.2
ERROR: No matching distribution found for cryptography3.3.2
The command ‘/bin/sh -c pip install -r requirements.txt’ returned a non-zero code: 1
changyu@ARTeam3D:~/arteam3d$ vim Dockerfile
解决方法 加入依赖
RUN apk add --no-cache g++ mariadb-dev build-base
RUN apk add --no-cache alpine-sdk gcc musl-dev python3-dev libffi-dev openssl-dev cargo jpeg-dev zlib-dev ffmpeg
alpine 版本安装后其实和ubuntu18.04 差不多大小,100m左右把,所以不推荐安装alpine版本,因为alpine属于轻量级的镜像,缺少很多依赖,会造成项目很不稳定。