- Notifications
You must be signed in to change notification settings - Fork196
bennzhang/docker-demo-with-simple-python-app
Folders and files
| Name | Name | Last commit message | Last commit date | |
|---|---|---|---|---|
Repository files navigation
This demo shows two steps:
- Install
docker-ceon Centos 7 - Build and run a simple docker image with a python+flask+gunicorn web application.
Refer tohttps://docs.docker.com/engine/installation/linux/docker-ce/centos/You can also findother OS installation docs from here.
$ sudo yum remove docker \ docker-common \ docker-selinux \ docker-enginesudo yum install -y yum-utils device-mapper-persistent-data lvm2sudo yum-config-manager --add-repo https://download.docker.com/linux/centos/docker-ce.reposudo yum install docker-cesudo systemctl start dockersudo docker run hello-worldOther commands:
- check docker status
sudo systemctl status docker.service- stop docker
sudo systemctl stop docker- uninstall docker-ce
sudo yum remove docker-ce- remove all images, container, volumes
sudo rm -rf /var/lib/dockerFROM python:2.7# Creating Application Source Code DirectoryRUN mkdir -p /usr/src/app# Setting Home Directory for containersWORKDIR /usr/src/app# Installing python dependenciesCOPY requirements.txt /usr/src/app/RUN pip install --no-cache-dir -r requirements.txt# Copying src code to ContainerCOPY . /usr/src/app# Application Environment variables#ENV APP_ENV developmentENV PORT 8080# Exposing PortsEXPOSE $PORT# Setting Persistent dataVOLUME ["/app-data"]# Running Python ApplicationCMD gunicorn -b :$PORT -c gunicorn.conf.py main:appNormally, image name convention is something like: {company/application-name}:{version-number}. In the demo, I just use{application-name}:{version-number}
sudo docker build -t my-python-app:1.0.1 .$ sudo docker imagesREPOSITORY TAG IMAGE ID CREATED SIZEmy-python-app 1.0.1 2b628d11ba3a 22 minutes ago 701.6 MBdocker.io/python 2.7 b1d5c2d7dda8 13 days ago 679.3 MBdocker.io/hello-world latest 05a3bd381fc2 5 weeks ago 1.84 kB2b628d11ba3a is the image ID, some commands based on the ID.
- tag
sudo docker tag 2b628d11ba3a my-python-app:1.0.1sudo docker tag 2b628d11ba3a my-python-app:latest- remove image
$ sudo docker rmi --force 2b628d11ba3a$ sudo docker run -d -p 8080:8080 my-python-app:1.0.1You can usesudo docker ps to list all running containers.
$ sudo docker psCONTAINER ID IMAGE COMMAND CREATED STATUS PORTS NAMES4de6041072b7 my-python-app:1.0.1 "/bin/sh -c 'gunicorn" 20 minutes ago Up 20 minutes 0.0.0.0:8080->8080/tcp elegant_kowalevski4de6041072b7 is the running container id. Some commands below are what you might need.
- display logs in running container
$ sudo docker logs 4de6041072b7[2017-10-23 20:29:49 +0000] [7] [INFO] Starting gunicorn 19.6.0[2017-10-23 20:29:49 +0000] [7] [INFO] Listening at: http://0.0.0.0:8080 (7)[2017-10-23 20:29:49 +0000] [7] [INFO] Using worker: gthread[2017-10-23 20:29:49 +0000] [11] [INFO] Booting worker with pid: 11[2017-10-23 20:29:49 +0000] [12] [INFO] Booting worker with pid: 12- stop your container
$ sudo docker stop 4de6041072b7- login inside the container
$ sudo docker exec -it 4de6041072b7 /bin/sh# ls /usr/src/appDockerfile README.md gunicorn.conf.py gunicorn_pid.txt main.py main.pyc requirements.txt# exit$ curl http://localhost:8080Hello WorldAbout
No description or website provided.
Topics
Resources
Uh oh!
There was an error while loading.Please reload this page.
Stars
Watchers
Forks
Releases
No releases published
Packages0
No packages published
Uh oh!
There was an error while loading.Please reload this page.