Analysis of Docker Containerized Deployment Python Application Process
- 2021-09-20 21:55:17
- OfStack
Simple application deployment
1. Directory structure:
The catalogue of Pythonpro #
test. py # File
The document requirements. txt #
Dockerfile # File
2. Write an Dockerfile file
# Based on mirroring
FROM python:3.6.4
# Create Code Folder Working Directory/code
RUN mkdir /code
# Copy current code file into 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 to execute when the container starts
CMD ["python","test.py"]
3. Create a container image
docker bulid -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, and test is the image just built.
--restart: The always container always restarts when it exits.
--privileged=true: Permissions required to execute files within the container.
Django Application Containerization
1. The directory structure, which I'm assuming exists at/home/Pythonpro.
The catalogue of Pythonpro #
manage. py # File
The main project # catalogue
The catalogue of apps #
Apparatus-requirements. txt # file
Dockerfile # File
run. sh # File
run. sh script
python /code/manage.py runserver 0.0.0.0:8000
2. Write an 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 a mirror image
docker bulid -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 port 8000 of container to host 6500
-v: Host directory/home/Pythonprot mapped to container directory/code
--name: Specifies the name of the container as web, the image just built by webtest
--restart: always container always restarts when exiting
--privileged=true: Permissions required to execute files in the container