博客
关于我
强烈建议你试试无所不能的chatGPT,快点击我
20170605
阅读量:5048 次
发布时间:2019-06-12

本文共 4693 字,大约阅读时间需要 15 分钟。

Creating the Dockerfile to Automatically Build the Image:

1.启动一个容器:

docker run -i -t -p 7000:80 centos7:cg /bin/bash

注释:centos7:cg这个镜像是在busybox +sshd+systemd+epel还加了监控工具sar+netstat等的镜像

  在镜像中的操作:    

41 yum update

42 yum -y install tar git curl nano wget dialog net-tools
43 yum -y install build-essential
44 yum install -y python python-dev python-distribute python-pip
45 yum install -y python python-dev python-distribute python-pip
46 yum install -y python python-dev*
47 yum install -y python-pip*
48 yum provides python-pip
49 yum provides pip
50 yum provides pip
51 yum search pip
52 pip
53 yum -y install pip
54 yum -y install pip*
55 yum -y --enablerepo=epel install python-pip
56 pip install flask
57 pip install --upgrade pip
58 pip install flask
59 mkdir my_application
60 cd my_application
61 vi app.py

  cat app.py

from flask import Flaskapp = Flask(__name__)@app.route("/")def hello():    return "Hello World!"if __name__ == "__main__":    app.run()

62 vi requirements.txt
63 pip install cherrypy
64 vi server.py

# Import your application as:# from app import application# Example:from app import app# Import CherryPyimport cherrypyif __name__ == '__main__':    # Mount the application    cherrypy.tree.graft(app, "/")    # Unsubscribe the default server    cherrypy.server.unsubscribe()    # Instantiate a new server object    server = cherrypy._cpserver.Server()    # Configure the server object    server.socket_host = "0.0.0.0"    server.socket_port = 80    server.thread_pool = 30    # For SSL Support    # server.ssl_module            = 'pyopenssl'    # server.ssl_certificate       = 'ssl/certificate.crt'    # server.ssl_private_key       = 'ssl/private.key'    # server.ssl_certificate_chain = 'ssl/bundle.crt'    # Subscribe this server    server.subscribe()    # Start the server engine (Option 1 *and* 2)    cherrypy.engine.start()    cherrypy.engine.block()

65 mkdir app

66 python server.py
67 pwd
68 history

最后在容器中的结构:

/my_application    |    |- requirements.txt  # File containing list of dependencies    |- /app              # Application module (which should have your app)    |- app.py            # WSGI file containing the "app" callable    |- server.py         # Optional: To run the app servers (CherryPy)

2.现在开始创建Dockerfile:

[root@node ~]# cat Dockerfile

############################################################
# Dockerfile to build Python WSGI Application Containers
# Based on jt
############################################################

# Set the base image to Ubuntu

FROM centos7:cg

# File Author / Maintainer

MAINTAINER Maintaner Name

# Add the application resources URL

#RUN echo "deb http://archive.ubuntu.com/ubuntu/ $(lsb_release -sc) main universe" >> /etc/apt/sources.list

# Update the sources list

RUN yum update

# Install basic applications

RUN yum install --enablerepo=epel -y tar git curl nano wget dialog net-tools

# Install Python and Basic Python Tools

RUN yum install --enablerepo=epel -y python python-dev python-distribute python-pip
#genxin
RUN pip install --upgrade pip
# Copy the application folder inside the container
ADD /my_application /my_application

# Get pip to download and install requirements:

RUN pip install -r /my_application/requirements.txt

# Expose ports

EXPOSE 80

# Set the default directory where CMD will execute

WORKDIR /my_application

# Set the default command to execute

# when creating a new container
# i.e. using CherryPy to serve the application
CMD python server.py &
[root@node ~]#

注意这里:ADD /my_application /my_application

我们可以换成:

RUN git clone [application repository URL] 至此我们用dockefile成功构建了一个镜像并访问成功 docker build -t my_application_img .

[root@node ~]# docker run -p 7001:80 -i -t --name jt my_application_img

[02/Jun/2017:20:05:49] ENGINE Bus STARTING
[02/Jun/2017:20:05:49] ENGINE Started monitor thread 'Autoreloader'.
[02/Jun/2017:20:05:49] ENGINE Started monitor thread '_TimeoutMonitor'.
[02/Jun/2017:20:05:49] ENGINE Serving on http://0.0.0.0
[02/Jun/2017:20:05:49] ENGINE Bus STARTED

 

 

 

 好了,成功用dockerfile发布了一个小代码

私有仓库搭建:

mkdir -p /opt/data/registry

因为是centos7所以都要在所有节点上修改:

vi /usr/lib/systemd/system/docker.service

ExecStart=/usr/bin/dockerd --insecure-registry 192.168.36.151:5000

systemctl daemon-reload

systemctl restart docker

启动一个注册容器:

docker run -d -p 5000:5000 -v /opt/data/registry:/var/lib/registry registry

为上传镜像打个标签:

docker tag busybox 192.168.36.151:5000/test

另外一个机器上面测试成功:

[root@node ~]# docker pull 192.168.36.151:5000/test

Using default tag: latest
Trying to pull repository 192.168.36.151:5000/test ...
latest: Pulling from 192.168.36.151:5000/test
Digest: sha256:32a0e4c673002bd7d4585587fb06ae9826cda9808317561b790ebef374bbb312

转载于:https://www.cnblogs.com/Jt00/p/6943687.html

你可能感兴趣的文章
Swift - 使用闭包筛选过滤数据元素
查看>>
alue of type java.lang.String cannot be converted to JSONObject
查看>>
搜索引擎选择: Elasticsearch与Solr
查看>>
JAVA设计模式之简单工厂模式与工厂方法模式
查看>>
③面向对象程序设计——封装
查看>>
【19】AngularJS 应用
查看>>
Spring
查看>>
Linux 系统的/var目录
查看>>
Redis学习---Redis操作之其他操作
查看>>
WebService中的DataSet序列化使用
查看>>
BZOJ 1200 木梳
查看>>
【Linux】【C语言】菜鸟学习日志(一) 一步一步学习在Linxu下测试程序的运行时间...
查看>>
hostname
查看>>
SpringBoot使用其他的Servlet容器
查看>>
关于cookie存取中文乱码问题
查看>>
k8s架构
查看>>
select 向上弹起
查看>>
mysql 多表管理修改
查看>>
group by order by
查看>>
bzoj 5252: [2018多省省队联测]林克卡特树
查看>>