python_web_app.rst 2.3 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970
  1. :title: Python Web app example
  2. :description: Building your own python web app using docker
  3. :keywords: docker, example, python, web app
  4. .. _python_web_app:
  5. Building a python web app
  6. =========================
  7. The goal of this example is to show you how you can author your own docker images using a parent image, making changes to it, and then saving the results as a new image. We will do that by making a simple hello flask web application image.
  8. **Steps:**
  9. .. code-block:: bash
  10. $ docker pull shykes/pybuilder
  11. We are downloading the "shykes/pybuilder" docker image
  12. .. code-block:: bash
  13. $ URL=http://github.com/shykes/helloflask/archive/master.tar.gz
  14. We set a URL variable that points to a tarball of a simple helloflask web app
  15. .. code-block:: bash
  16. $ BUILD_JOB=$(docker run -d -t shykes/pybuilder:latest /usr/local/bin/buildapp $URL)
  17. Inside of the "shykes/pybuilder" image there is a command called buildapp, we are running that command and passing the $URL variable from step 2 to it, and running the whole thing inside of a new container. BUILD_JOB will be set with the new container_id.
  18. .. code-block:: bash
  19. $ docker attach $BUILD_JOB
  20. [...]
  21. We attach to the new container to see what is going on. Ctrl-C to disconnect
  22. .. code-block:: bash
  23. $ BUILD_IMG=$(docker commit $BUILD_JOB _/builds/github.com/hykes/helloflask/master)
  24. Save the changed we just made in the container to a new image called "_/builds/github.com/hykes/helloflask/master" and save the image id in the BUILD_IMG variable name.
  25. .. code-block:: bash
  26. $ WEB_WORKER=$(docker run -d -p 5000 $BUILD_IMG /usr/local/bin/runapp)
  27. Use the new image we just created and create a new container with network port 5000, and return the container id and store in the WEB_WORKER variable.
  28. .. code-block:: bash
  29. $ docker logs $WEB_WORKER
  30. * Running on http://0.0.0.0:5000/
  31. view the logs for the new container using the WEB_WORKER variable, and if everything worked as planned you should see the line "Running on http://0.0.0.0:5000/" in the log output.
  32. **Video:**
  33. See the example in action
  34. .. raw:: html
  35. <div style="margin-top:10px;">
  36. <iframe width="720" height="350" src="http://ascii.io/a/2573/raw" frameborder="0"></iframe>
  37. </div>
  38. Continue to the `base commands`_
  39. .. _base commands: ../commandline/basecommands.html