Artigo Diretório
- git add origin
- dockerfile
- Script de embalagem, recipiente de auto-inicialização de embalagem
- Explique a implantação separada da configuração nginx entre front ends e back ends
- ------------- Fim do foco ~~~~~~~~~~~~~~~~~~~~~~~
- espelho centos7
- usar
- Montar contêiner de volume de dados
- Construir imagem python3612
- Use python3612
- Configurar proxy
- Crie nginx + py36 diretamente
- Comando de construção
- usar
- Monte o volume de dados
- Inicie o serviço após entrar no contêiner
git add origin
Endereço do espelho [email protected]: mengkaibulusili / centos7.git
git remote add origin [email protected]:mengkaibulusili/centos7.git
dockerfile
Quando o contêiner está em execução, ele deve tentar impedir a camada de armazenamento do contêiner de gravar operações.Para aplicativos de banco de dados que precisam armazenar dados dinâmicos, os arquivos de banco de dados devem ser armazenados em um volume.
volume A localização do volume montado
Deixe o contêiner 2 montar o conteúdo de dados do contêiner 1
docker executar --name <contêiner 2> --volumes-from <nome do contêiner 1>
Script de embalagem, recipiente de auto-inicialização de embalagem
Crie um contêiner de volume de dados primeiro
cat << EOF > DockerfileDataVolum
FROM alpine
COPY shopServer /root/shopServer
VOLUME /root/shopServer
CMD ["/bin/bash"]
docker build -f DockerfileDataVolum -t registry.cn-hangzhou.aliyuncs.com/mkmk/centos:VolumeData .
Crie um contêiner de aplicativo baseado no contêiner nginx django
Pequenos detalhes bloqueando o lançamento do contêiner
/root/shopServer/startServer.sh content
cd /root/shopServer && \
source /root/.bashrc && \
pip3 install -r requirements.txt && \
uwsgi -x /root/shopServer/shopServer.xml && \
nginx -t -c /root/shopServer/nginx/myNginx.conf && \
nginx -c /root/shopServer/nginx/myNginx.conf
# tail -f 可以阻塞 容器执行网命令退出
tail -f /dev/null
cat << EOF > shopServerDF
FROM registry.cn-hangzhou.aliyuncs.com/mkmk/centos:Py36Nginx
CMD ["/bin/bash","/root/shopServer/startServer.sh"]
docker build -f shopServerDF -t registry.cn-hangzhou.aliyuncs.com/mkmk/centos:shopServer .
Usar contêiner de dados
//新建数据容器但是不用运行
docker create --name djangoVolume registry.cn-hangzhou.aliyuncs.com/mkmk/centos:VolumeData
docker stop centos7base | docker rm centos7base
//运行并 挂载数据容器
docker run -d --name centos7base -p 13000:3000 -p 15000:5000 --volumes-from djangoVolume --privileged=true registry.cn-hangzhou.aliyuncs.com/mkmk/centos:shopServer
Configurar nginx uwsgi
nginx -t -c /root/shopServer/myNginx.conf
nginx -c /root/shopServer/myNginx.conf
查看服务是否正常启动
ps -ef|grep uwsgi
Pausar script de servidor
nginx -s stop
pkill -9 uwsgi
pkill -9 python3
Explique a implantação separada da configuração nginx entre front ends e back ends
user root;
# 容器内设置root 权限启动 应用, 否则部分文件夹无法访问
events {
#最大连接数
worker_connections 1024;
}
http {
include mime.types;
default_type application/octet-stream;
sendfile on;
# 扩大请求头 的体积上限, 默认 4k
client_header_buffer_size 16k;
large_client_header_buffers 10 1m;
server {
listen 5000;
server_name _; #改为自己的域名,没域名修改为127.0.0.1:80
charset utf-8;
# django 后端 api 服务
location /api/ {
include uwsgi_params;
uwsgi_pass 127.0.0.1:8999; #端口要和uwsgi里配置的一样
uwsgi_param UWSGI_SCRIPT shopServer.wsgi; #wsgi.py所在的目录名+.wsgi
uwsgi_param UWSGI_CHDIR /root/shopServer/; #项目路径
}
# 静态资源路径 也可以不配置,
#因为我们使用的是 webpack 打包的应用程序
# 只要部署了 build 文件即可
location /static/ {
alias /root/shopServer/templates/static/; #静态资源路径
}
# 部署前台 资源 的 打包路径
location / {
index index.html;
alias /root/shopServer/build/;
}
access_log /root/shopServer/server.log;
error_log /root/shopServer/server.error.log;
}
}
------------- Fim do foco ~~~~~~~~~~~~~~~~~~~~~~~
espelho centos7
Configure a codificação chinesa
&& yum -y install gcc automake autoconf libtool make wget \
&& yum -y install kde-l10n-Chinese telnet \
&& yum -y install glibc-common \
&& yum clean all \
&& localedef -c -f UTF-8 -i zh_CN zh_CN.utf8 \
&& echo -e 'export LANG="zh_CN.UTF-8"\nexport LC_ALL="zh_CN.UTF-8"' > /etc/locale.conf \
&& source /etc/locale.conf \
ENV LC_ALL zh_CN.UTF-8
ENV LANG zh_CN.UTF-8
cd centos7
docker build -t registry.cn-hangzhou.aliyuncs.com/mkmk/centos:base7 .
usar
docker run -d --name centos7base -p 13000:3000 -p 15000:5000 --privileged=true registry.cn-hangzhou.aliyuncs.com/mkmk/centos:base7 init
Montar contêiner de volume de dados
Crie um contêiner de volume de dados primeiro
Construir imagem python3612
docker build -f DockerfilePy3612 -t registry.cn-hangzhou.aliyuncs.com/mkmk/centos:base7Py3612 .
Use python3612
docker stop centos7base | docker rm centos7base
docker run -d --name centos7base -p 13000:3000 -p 15000:5000 --privileged=true registry.cn-hangzhou.aliyuncs.com/mkmk/centos:base7Py3612 init
Configurar proxy
export http_proxy="http://192.168.1.6:7890/"
export https_proxy="http://192.168.1.6:7890/"
Crie nginx + py36 diretamente
FROM scratch
ADD centos-7-x86_64-docker.tar.xz /
COPY nginx.repo /etc/yum.repos.d/nginx.repo
COPY get-pip.py /usr/local/python36/get-pip.py
COPY sqlite-autoconf-3330000.tar.gz /root/sqlite-autoconf-3330000.tar.gz
ENV GPG_KEY 0D96DF4D4110E5C43FBFB17F2D347EA6AA65421D
ENV PYTHON_VERSION 3.6.12
# if this is called "PIP_VERSION", pip explodes with "ValueError: invalid truth value '<VERSION>'"
ENV PYTHON_PIP_VERSION 20.2.2
# https://github.com/pypa/get-pip
ENV PYTHON_GET_PIP_URL https://github.com/pypa/get-pip/raw/5578af97f8b2b466f4cdbebe18a3ba2d48ad1434/get-pip.py
ENV PYTHON_GET_PIP_SHA256 d4d62a0850fe0c2e6325b2cc20d818c580563de5a2038f917e3cb0e25280b4d1
RUN export http_proxy="http://192.168.1.6:7890/" \
&& export https_proxy="http://192.168.1.6:7890/" \
&& sed -i "s/#baseurl/baseurl/g" /etc/yum.repos.d/CentOS-Base.repo \
&& sed -i "s/mirrorlist=http/#mirrorlist=http/g" /etc/yum.repos.d/CentOS-Base.repo \
&& sed -i "s@http://mirror.centos.org@https://mirrors.huaweicloud.com@g" /etc/yum.repos.d/CentOS-Base.repo \
&& yum clean all \
&& yum makecache \
&& yum -y install openssl-devel bzip2-devel expat-devel gdbm-devel readline-devel sqlite-devel \
&& yum -y install gcc automake autoconf libtool make wget \
&& yum -y install kde-l10n-Chinese telnet \
&& yum -y install glibc-common \
&& yum clean all \
&& localedef -c -f UTF-8 -i zh_CN zh_CN.utf8 \
&& echo -e 'export LANG="zh_CN.UTF-8"\nexport LC_ALL="zh_CN.UTF-8"' > /etc/locale.conf \
&& source /etc/locale.conf \
&& cd /root \
&& tar -xf sqlite-autoconf-3330000.tar.gz \
&& cd sqlite-autoconf-3330000 \
&& ./configure --enable-optimizations \
&& make && make install \
&& ln -s /usr/local/bin/sqlite3 /usr/bin/sqlite3 \
&& cd /root \
&& rm -rf /root/sqlite-autoconf-3330000* \
&& set -ex \
&& wget -O python.tar.xz "https://mirrors.huaweicloud.com/python/${PYTHON_VERSION%%[a-z]*}/Python-$PYTHON_VERSION.tar.xz" \
&& wget -O python.tar.xz.asc "https://mirrors.huaweicloud.com/python/${PYTHON_VERSION%%[a-z]*}/Python-$PYTHON_VERSION.tar.xz.asc" \
&& export GNUPGHOME="$(mktemp -d)" \
&& {
command -v gpgconf > /dev/null && gpgconf --kill all || :; } \
&& rm -rf "$GNUPGHOME" python.tar.xz.asc \
&& mkdir -p /usr/src/python \
&& tar -xJC /usr/src/python --strip-components=1 -f python.tar.xz \
&& rm python.tar.xz \
\
&& cd /usr/src/python \
&& LD_RUN_PATH=/usr/local/lib ./configure \
--prefix=/usr/local/python36 \
--enable-loadable-sqlite-extensions \
--enable-optimizations \
--enable-option-checking=fatal \
--enable-shared \
--with-system-expat \
--with-system-ffi \
--without-ensurepip \
&& LD_RUN_PATH=/usr/local/lib make -j "$(nproc)" \
# setting PROFILE_TASK makes "--enable-optimizations" reasonable: https://bugs.python.org/issue36044 / https://github.com/docker-library/python/issues/160#issuecomment-509426916
PROFILE_TASK='-m test.regrtest --pgo \
test_array \
test_base64 \
test_binascii \
' \
&& LD_RUN_PATH=/usr/local/lib make install \
&& cd /usr/local/python36 \
&& rm -rf /usr/src/python \
&& ln -s /usr/local/python36/lib/libpython3.6m.so.1.0 /usr/lib/libpython3.6m.so.1.0 \
&& ldconfig \
&& ln -s /usr/local/python36/bin/idle3 /usr/bin/idle3 \
&& ln -s /usr/local/python36/bin/pydoc3 /usr/bin/pydoc3 \
&& ln -s /usr/local/python36/bin/python3 /usr/bin/python3 \
&& ln -s /usr/local/python36/bin/python3-config /usr/bin/python3-config \
&& /usr/bin/python3 --version \
&& /usr/bin/python3 get-pip.py \
--disable-pip-version-check \
--no-cache-dir \
"pip==$PYTHON_PIP_VERSION" \
&& rm -f get-pip.py \
&& ln -s /usr/local/python36/bin/pip3 /usr/bin/pip3 \
&& /usr/bin/pip3 config set global.index-url https://pypi.tuna.tsinghua.edu.cn/simple \
&& yum-config-manager --enable nginx-stable \
&& yum install nginx -y \
&& echo 'export PATH=/usr/local/python36/bin:$PATH' >> /root/.bashrc \
&& /usr/bin/pip3 install uwsgi
LABEL \
org.label-schema.schema-version="1.0" \
org.label-schema.name="CentOS Base Image" \
org.label-schema.vendor="CentOS" \
org.label-schema.license="GPLv2" \
org.label-schema.build-date="20200809" \
org.opencontainers.image.title="CentOS Base Image" \
org.opencontainers.image.vendor="CentOS" \
org.opencontainers.image.licenses="GPL-2.0-only" \
org.opencontainers.image.created="2020-08-09 00:00:00+01:00"
ENV LC_ALL zh_CN.UTF-8
ENV LANG zh_CN.UTF-8
CMD ["init"]
Comando de construção
Certifique-se de que sua rede está disponível
docker build -f DockerfilePy3612Nginx -t registry.cn-hangzhou.aliyuncs.com/mkmk/centos:Py36Nginx .
usar
docker stop centos7base | docker rm centos7base
docker run -d --name centos7base -p 13000:3000 -p 15000:5000 --privileged=true registry.cn-hangzhou.aliyuncs.com/mkmk/centos:Py36Nginx init
Monte o volume de dados
Crie um contêiner de volume de dados primeiro
cat << EOF > DockerfileDataVolum
FROM alpine
COPY shopServer /root/shopServer
VOLUME /root/shopServer
CMD ["/bin/bash"]
docker build -f DockerfileDataVolum -t registry.cn-hangzhou.aliyuncs.com/mkmk/centos:VolumeData .
Novos dados de montagem de contêiner de aplicativo
//新建数据容器但是不用运行
docker create --name djangoVolume registry.cn-hangzhou.aliyuncs.com/mkmk/centos:VolumeData
docker stop centos7base | docker rm centos7base
//运行并 挂载数据容器
docker run -d --name centos7base -p 13000:3000 -p 15000:5000 --volumes-from djangoVolume --privileged=true registry.cn-hangzhou.aliyuncs.com/mkmk/centos:Py36Nginx init
Construir o contêiner
docker build -f DockerfilePy3612Nginx -t registry.cn-hangzhou.aliyuncs.com/mkmk/centos:Py36Nginx .
Inicie o serviço após entrar no contêiner
pip3 install -r requirements.txt && python3 manage.py runserver 0.0.0.0:5000