9. Dockerfile actual operation (the image and packed into python app run)

1. Create and enter the flask-hello-world

  mkdir flask-hello-world && cd flask-hello-world

2. Write python file app.py

  from flask import Flask

  app = Flask(__name__)

  @app.route('/')

  def hello():

    return "hello docker"

  if __name__ == '__main__':

    app.run()

3. Write Dockerfile file

  FROM python: 2.7 #base image is python: 2.7

  LABEL maintainer = "eaon <[email protected]>" # tag developed for eaon and mailbox

  RUN pip install flask # installation flask expand

  COPY app.py / app / # app.py will be copied to / app under

  WORKDIR / app # define the working directory is / app

  EXPOSE 5000 # exposed port 

  CMD python app.py # app.py file execution

4. Create an image by Dockerfile

  docker build -t [image_name] .

5. Error investigation

  docker run -it  [image_id]  /bin/bash

6. The operation and running in the container

  docker exec -it [container_id] / bin / bash # by writing shell scripts into the container

  docker exec -it [container_id] python # into the container by writing python

  docker exec -it [container_id] ip a # print out operation of the container ip address

 

Guess you like

Origin www.cnblogs.com/zonehoo/p/11284548.html