Analysis of the process of deploying Python applications in Docker containers

Analysis of the process of deploying Python applications in Docker containers

Simple application deployment

1. Directory structure:

└── Pythonpro #Directory└── test.py #File└── requirements.txt #File└── Dockerfile #File

2. Write the Dockerfile file

# Based on the image
FROM python:3.6.4
# Create a code folder working directory/code
RUN mkdir /code
#Copy the current code file to the container/code
COPY ./code
# Install required packages
RUN pip install -r /code/requirements.txt -i https://pypi.douban.com/simple
# Specify the working directory of cmd/code
WORKDIR /code
#Commands executed when the container starts
CMD ["python","test.py"]

3. Create a container image

docker build -t test .

4. Run the container

docker run -it --name test --restart always --privileged=true python-test
--name: specifies the name of the container as python-test, where test is the image just built.

--restart: always The container is always restarted when it exits.

--privileged=true: The permissions required to execute files in the container.

Django application containerization

1. Directory structure, I assume that this directory exists in /home/Pythonpro.

└── Pythonpro #Directory└── manage.py #File└── Main Project #Directory└── apps #Directory└── requirements.txt #File└── Dockerfile #File└── run.sh #File

run.sh script

python /code/manage.py runserver 0.0.0.0:8000

2. Write the Dockerfile file

FROM python:3.6.4
RUN mkdir /code \
&&apt-get update \
&&apt-get -y install freetds-dev \
&&apt-get -y install unixodbc-dev
COPY ./code 
RUN pip install -r /code/requirements.txt -i https://pypi.douban.com/simple
WORKDIR /code
CMD ["/bin/bash","run.sh"]

3. Build an Image

docker build -t webtest .

4. Run the container

docker run -it -p 6500:8000 -v /home/Pythonpro:/code --name web --restart always --privileged=true webtest

-p: Map the container's port 8000 to the host's port 6500

-v: The host directory /home/Pythonprot is mapped to the container directory /code

--name: specifies the name of the container as web, the image just built by webtest

--restart: always The container is always restarted when it exits

--privileged=true: Permissions required to execute files in the container

The above is the full content of this article. I hope it will be helpful for everyone’s study. I also hope that everyone will support 123WORDPRESS.COM.

You may also be interested in:
  • About Python connecting to Cassandra container for query
  • How to build a deep learning environment running Python in Docker container
  • Detailed explanation of Python basic syntax containers
  • Python statistics hashable objects container Counter detailed explanation
  • Python container summary
  • Python container built-in general function operations

<<:  Markup language - CSS layout

>>:  Native JS to achieve digital table special effects

Recommend

How to check and organize website files using Dreamweaver8

What is the purpose of creating your own website u...

How to make ApacheBench support multi-url

Since the standard ab only supports stress testin...

Kali Linux Vmware virtual machine installation (illustration and text)

Preparation: 1. Install VMware workstation softwa...

Use xshell to connect to the Linux server

Benefits of using xshell to connect to Linux We c...

How to implement the prototype pattern in JavaScript

Overview The prototype pattern refers to the type...

Example of using JSX to build component Parser development

Table of contents JSX environment construction Se...

Example code for Html layered box-shadow effect

First, let’s take a look at the picture: Today we...

MySQL msi installation tutorial under windows10 with pictures and text

1. Download 1. Click the latest download from the...

Tutorial on deploying nginx+uwsgi in Django project under Centos8

1. Virtual environment virtualenv installation 1....

MySQL cross-table query and cross-table update

Friends who have some basic knowledge of SQL must...

Detailed explanation of mysql transaction management operations

This article describes the MySQL transaction mana...

9 ways to show and hide CSS elements

In web page production, displaying and hiding ele...

MySQL view principles and basic operation examples

This article uses examples to illustrate the prin...