python engineering package docker image file

Build a python environment

Double-click to open the docker

 

Then download the image:
Docker pull Ubuntu

Ubuntu container into the interactive system:
Docker RUN -i -t ubuntu / bin / bash
-t is to start the terminal
-i is allowed to interact
this time knocking the python command will find no python

install python under Ubuntu:
APT-GET Update
APT-GET install python3
# python installed with input python3 try
# install pip
APT-GET-install python3 pip (this will also install a command like python2.7)
# installed pip input pip try
APT-GET-dev python3 install
APT-GET install OpenSSL
APT-GET-dev for libssl install
APT-GET install libffi-dev

View success:
Docker RUN -v / the Users / ZJL / python3i / py3image: / py3image -w / py3image Ubuntu python3 a.py
-v parameter, a colon before host directory must be an absolute path, after a colon in the mirror hanging carrier path
-w parameter specifying the current working directory mirror
create a a.py in native / Users / zjl / python3i / py3image , performed

The folding of the python container:
command: docker commit <container id> new image name
docker commit 1604777a778c docker / python3env

Batch installation library:
command: docker -v host directory: -w container vessel directory mirroring the current working directory name command
docker run -v / Users / zjl / python3i / py3image: / py3image -w / py3image ubuntu pip3 install -r requirements. TXT
-v parameter, a colon before host directory must be an absolute path, after the colon is the path in the mirror mount
-w parameter, is designated as the current working directory mirror

Since then boot image will be initialized to look like once it is re-packaged container, preserve the contents
docker commit 62d4eefe7e62 python3env

Into the container Interactive:
Docker RUN -i -t -v / the Users / ZJL / python3i / py3image: / py3image -w / py3image python3env / bin / bash
knock python Go to interactive, import just installed a library
or
create a new a.py, import several newly installed library which
then execute:
Docker RUN -v / the Users / ZJL / python3i / py3image: / py3image -w / py3image python3env Python a.py
no mistake that success


Export image:
command:
Docker /Users/zjl/Desktop/aaa/python3env.tar python3env the Save -o
-o parameter, the output file
need to export the file path name to drink
need to export the image name

 

Import image:
command:
Docker Import /Users/zjl/Desktop/aaa/python3env.tar python3env: 1.1
Import import, image file path and name, create mirrored the name and version


Container and mirrored understanding:
image file is read, feels like a file system with iOS
containers are used to run and read and write access to the mirror, such as ios installed system, itself also packaged as a longer ios file, after the container is closed without saving the modified data, open again to restore the original image data


docker inner container python program execution flask:
Modify the flask Host = '0.0.0.0'
command:
docker -p 5001 RUN: 5000 -v / the Users / ZJL / Desktop / AAA / Spider: / py3image -w / py3image python3env runflask python. Py
-p 5001: 5000, the container 5000 5001 port mapping host port, a host port before the colon, the colon is a container port


flask proceedings 5000 container port, but the port is mapped to the IP 5001, IP hosts to access the docker services

When the python with docker container execution environment within which the python connected to a database program, or other what needs to be set not to use the IP 127.0.0.1

 

the windows start flask:
Do not forget = Host '0.0.0.0'
Docker RUN -p 5001: 5000 -v D: \ PycharmProjects \ Spider: / py3image -w / py3image python3env python3 runflask.py

Guess you like

Origin www.cnblogs.com/hanzeng1993/p/11416792.html