1. Choose a suitable basic image, you can bring basic python3.6, C++ environment gcc, java SDK, etc., so you don’t need to install it in the container later
docker pull mirror command
docker pull [OPTIONS] NAME[:TAG|@DIGEST]
docker pull 镜像链接:版本号
2. Refer to the previous blog post to install various extension packages, including TensorFlow, jpype1, here you can use pip to install
Last blog post address: https://blog.csdn.net/qq_22472047/article/details/104474561
3. If java is not installed, you can download the java SDK installation package locally and upload it to the docker designated container
Download the specified version of the java SDK
Download link: https://www.oracle.com/cn/java/technologies/javase-jdk8-downloads.html
Create a folder where the java environment is stored
mkdir -p /usr/lib/jvm
Upload to the specified container of docker
1) Obtain the container id
docker ps -a
2) Get the complete container id
docker inspect -f '{
{.Id}}' container_id
3) Upload local files to the docker container
docker cp 本地文件路径 ID全称:容器路径
4) Unzip the java environment installation package
tar -zxvf jdk-8u131-linux-x64.tar.gz -C /usr/lib/jvm
5) Set environment variables
vim /etc/profile
When using a docker container, sometimes vim is not installed inside, and when you press the vim command, it prompts: vim: command not found. At this time, you need to install vim, but when you press the apt-get install vim command, it prompts:
Reading package lists... Done
Building dependency tree
Reading state information... Done
E: Unable to locate package vim
At this time you need to knock:
apt-get update
The function of this command is to synchronize the indexes of the sources listed in /etc/apt/sources.list and /etc/apt/sources.list.d so that the latest software packages can be obtained.
Wait until the update is complete and then type the command
apt-get install vim
You can successfully install vim
At this time, you can configure the java environment variable and edit the configuration file
export JAVA_HOME=/usr/lib/jvm/jdk1.8.0_231
export CLASSPATH=.:$JAVA_HOME/lib/dt.jar:$JAVA_HOME/lib/tools.jar
export PATH=$PATH:$JAVA_HOME/bin
6) Reload the configuration file
source /etc/profile
This allows the configuration to take effect immediately without restarting
7) Test it
java -version
display
java version "1.8.0_131"
Java(TM) SE Runtime Environment (build 1.8.0_131-b11)
Java HotSpot(TM) 64-Bit Server VM (build 25.131-b11, mixed mode)
That is, the configuration is successful, and the whole installation process is over.
4. Install pyhanlp
pip install pyhanlp -i https://pypi.doubanio.com/simple/ --trusted-host pypi.doubanio.com
5. Check if pyhanlp is installed successfully
After entering the python environment, import the pyhanlp package, after success, no error will be reported and some necessary model files will be loaded
from pyhanlp import *