External access to the container (b) --Docker

Creative Commons License Copyright: Attribution, allow others to create paper-based, and must distribute paper (based on the original license agreement with the same license Creative Commons )
Example: Docker run Flask Web applications, external access to the application container
1, running CentOS mirrors

[root@instance-mtfsf05r ~]# docker run -it centos

2, the container module easy_install

[root@09a475fade35 /]# yum install python-setuptools -y

3, the mounting module Flask

[root@09a475fade35 /]# easy_install flask

Verify that the installation was successful:import flask

[root@2471dd89bbc1 /]# python

Python 2.7.5 (default, Oct 30 2018, 23:45:53)
[GCC 4.8.5 20150623 (Red Hat 4.8.5-36)] on linux2
Type "help", "copyright", "credits" or "license" for more information.
>>> import flask
>>>
4, write a script Flask Web

New Flask script file in your home directory flask-web.py :

[root@2471dd89bbc1 /]# cd home

[root@2471dd89bbc1 home]# ls

[root@2471dd89bbc1 home]# touch flask-web.py

Need to use vim, install vim:

[root@2471dd89bbc1 home]# yum install vim -y

[root@2471dd89bbc1 home]# vim flask-web.py

flask-web.py

from flask import Flask
app= Flask(__name__)

@app.route('/')
def index():
        return 'Flask Application!'

if __name__ == '__main__':
        app.run(host = '0.0.0.0',port = 5000)

Run this script file, verify that wrong:

[root@2471dd89bbc1 home]# python flask-web.py
Here Insert Picture Description

5, exit the container, the container produced record

[root@2471dd89bbc1 home]# exit

6, the container to submit records to build the mirror

[root@instance-mtfsf05r ~]# docker commit 2471dd89bbc1 test/flask_web

View Mirror:[root@instance-mtfsf05r ~]# docker image ls
Here Insert Picture Description

7, operation of generating image container

Use: [root@instance-mtfsf05r ~]# docker run -d -p 7000:5000 test/flask_webthere is no action, you need to run the script, the vessel continued to run:

[root@instance-mtfsf05r ~]# docker run -d -p 7000:5000 test/flask_web python /home/flask-web.py

"7000" is the host (I have here is the cloud host) port, "5000" is the application port Docker in the container. External Access homed host "7000" is the port access Docker Docker port in the corresponding 5000 application.

8, access to the container application

In your browser, enter: 106.12.115.123: 7000 / (Host IP + port number) will have access to the cloud host Flask Web applications:
Here Insert Picture Description

External access to the container (a): https://blog.csdn.net/Thanlon/article/details/92805233

Guess you like

Origin blog.csdn.net/Thanlon/article/details/92806950