当前位置:   article > 正文

dockerfile构建自定义镜像(以python3.6为例)_dockfile 制作centos python3 案例

dockfile 制作centos python3 案例

实例-基于Centos7.6的Python3.6.8镜像

以centos7.6为基础镜像,构建带有python3.6.8的镜像

FROM centos:7.6.1810
ENV PATH $PATH:/usr/local/python3/bin/
ENV PYTHONIOENCODING utf-8
RUN set -ex \
	&& mv /etc/yum.repos.d/CentOS-Base.repo /etc/yum.repos.d/CentOS-Base.repo.backup \
	&& curl -o /etc/yum.repos.d/CentOS-Base.repo http://mirrors.aliyun.com/repo/Centos-7.repo \
	&& yum makecache \
	&& sed -i -e '/mirrors.cloud.aliyuncs.com/d' -e '/mirrors.aliyuncs.com/d' /etc/yum.repos.d/CentOS-Base.repo \
	&& yum -y install zlib-devel bzip2-devel openssl-devel ncurses-devel sqlite-devel readline-devel tk-devel gcc make wget \
	&& yum clean all \
	&& mkdir /usr/local/python3 \
	&& wget https://www.python.org/ftp/python/3.6.8/Python-3.6.8.tar.xz \
	&& tar -xvJf  Python-3.6.8.tar.xz && rm -f Python-3.6.8.tar.xz \
	&& cd Python-3.6.8 \
	&& ./configure prefix=/usr/local/python3 \
	&& make && make install \
	&& cd .. \
	&& rm -rf Python-3.6.8
CMD ["usr","bin","bash"]
  • 1
  • 2
  • 3
  • 4
  • 5
  • 6
  • 7
  • 8
  • 9
  • 10
  • 11
  • 12
  • 13
  • 14
  • 15
  • 16
  • 17
  • 18
  • 19

实例-基于Centos7.6的scrapyd服务镜像

FROM centos:7.6.1810
WORKDIR /server
COPY . /server
ENV SCRAPYD_PORT 6800
RUN set -ex \
	&& yum -y install zlib-devel bzip2-devel openssl-devel ncurses-devel sqlite-devel readline-devel tk-devel gcc make wget \
	&& yum clean all \
	&& mkdir /usr/local/python3 \
	&& wget https://www.python.org/ftp/python/3.6.8/Python-3.6.8.tar.xz \
	&& tar -xvJf  Python-3.6.8.tar.xz && rm -f Python-3.6.8.tar.xz \
	&& cd Python-3.6.8 \
	&& ./configure prefix=/usr/local/python3 \
	&& make && make install \
	&& ln -s /usr/local/python3/bin/python3.6 /usr/local/bin/python3 \
	&& ln -s /usr/local/python3/bin/pip3 /usr/local/bin/pip3 \
	&& cd .. \
	&& rm -rf Python-3.6.8 \
	&& pip3 install -r requirements.txt \
	&& ln -s /usr/local/python3/bin/scrapyd /usr/local/bin/scrapyd \
	&& sed -i 's#127.0.0.1#0.0.0.0#g' /usr/local/python3/lib/python3.6/site-packages/scrapyd/default_scrapyd.conf
CMD ['scrapyd']
  • 1
  • 2
  • 3
  • 4
  • 5
  • 6
  • 7
  • 8
  • 9
  • 10
  • 11
  • 12
  • 13
  • 14
  • 15
  • 16
  • 17
  • 18
  • 19
  • 20
  • 21

启动方式

docker run -d -p 6800:6800 image_id scrapyd

访问本机内网地址6800端口即可。

实例-基于Centos7.6的scrapyd服务镜像(可自定义端口)

FROM centos:7.6.1810
WORKDIR /server
COPY . /server
ENV SCRAPYD_PORT 6800
RUN set -ex \
	&& yum -y install zlib-devel bzip2-devel openssl-devel ncurses-devel sqlite-devel readline-devel tk-devel gcc make wget \
	&& yum clean all \
	&& mkdir /usr/local/python3 \
	&& wget https://www.python.org/ftp/python/3.6.8/Python-3.6.8.tar.xz \
	&& tar -xvJf  Python-3.6.8.tar.xz && rm -f Python-3.6.8.tar.xz \
	&& cd Python-3.6.8 \
	&& ./configure prefix=/usr/local/python3 \
	&& make && make install \
	&& ln -s /usr/local/python3/bin/python3.6 /usr/local/bin/python3 \
	&& ln -s /usr/local/python3/bin/pip3 /usr/local/bin/pip3 \
	&& cd .. \
	&& rm -rf Python-3.6.8 \
	&& pip3 install -r requirements.txt \
	&& ln -s /usr/local/python3/bin/scrapyd /usr/local/bin/scrapyd \
	&& sed -i 's#127.0.0.1#0.0.0.0#g' /usr/local/python3/lib/python3.6/site-packages/scrapyd/default_scrapyd.conf \
	&& echo '#!/bin/bash' >>runserver.sh \
	&& echo 'sed -i "s#6800#$SCRAPYD_PORT#g" /usr/local/python3/lib/python3.6/site-packages/scrapyd/default_scrapyd.conf' >>runserver.sh \
	&& echo 'scrapyd' >> runserver.sh
CMD ["bin","bash"]

  • 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

启动方式,不指定SCRAPYD_PORT则默认为6800

docker run -d -e SCRAPYD_PORT=6999 -p 6999:6999 image_id /bin/bash runserver.sh

  • SCRAPYD_PORT :scrapyd运行端口
  • 6999:6999 :与宿主机的端口映射

其他参数

#设置工作目录
WORKDIR /app
#Copy the current directory contents into the container at /app
COPY . /app
#Make port 80 available to the world outside this container
EXPOSE 80
#Define environment variable
ENV NAME World

声明:本文内容由网友自发贡献,不代表【wpsshop博客】立场,版权归原作者所有,本站不承担相应法律责任。如您发现有侵权的内容,请联系我们。转载请注明出处:https://www.wpsshop.cn/w/花生_TL007/article/detail/687295
推荐阅读
相关标签
  

闽ICP备14008679号