Writing this blog is mainly about thinking about where to put the bookmarks every time, so write down your notes here.
0. Environment
ubuntu16.04
1. tensorflow, keras, pytorch can use virtualenv
A better method used in a blog:
https://www.jianshu.com/p/6bf33e479753
Create a new virtual environment, activate a virtual environment, close a virtual environment, and delete a virtual environment.
Under windows:
打开cmd
pip install -i https://pypi.tuna.tsinghua.edu.cn/simple virtualenv
virtualenv env
cd env/Scripts/
activate
关闭的话:
deactivate
ubuntu 下 :
打开terminal
pip install -i https://pypi.tuna.tsinghua.edu.cn/simple virtualenv
virtualenv env
cd env
source ./bin/activate
关闭的话:
deactivate
2.caffe uses docker
Learn here.
3.tensorflow uses docker
3.1 Create a virtual environment and container for the first time
When we need to compile tensorflow, we can use docker to create a tensorflow virtual environment. Since docker is already installed on the server, directly use the following command to pull the image to the server:
docker pull tensorflow/tensorflow:1.12.0-gpu-py3
After completing the above steps, the virtual environment of tensorflow has been created. Use docker images to view the image:
docker images
Create a new sh file and run it. (Sh ./your_sh.sh)
#!/bin/bash
nvidia-docker run -m 8GB -it --net=host \
-v 实际物理被映射的目录:虚拟目录 \
--name (我的容器名称,可以随便定义,但是不能重复) tensorflow/tensorflow:1.12.0-gpu-py3 /bin/bash
例子:
#!/bin/bash
nvidia-docker run -m 8GB -it --net=host \
-v /home/tensorflow/:/opt/tensorflow/ \
--name tf_test tensorflow/tensorflow:1.12.0-gpu-py3 /bin/bash
nvidia-docker: Indicates the GPU used;
-v before: after: the virtual address of the latter corresponds to the actual physical mapped directory; that is to say, when we use the above statement to create the container of our sentence, switch to the virtual directory, the files and files inside Folders are under the actual physical mapped directory.
3.2 Exit the current container
单个终端时:
exit
多个终端时:
docker container stop
3.2 Enter the designated container again
Taking the example I wrote above as an example, it looks like this.
单个终端时:
docker start 我的容器
docker attach 我的容器
使用上述的即使打开多个终端进入同一个容器,但是显示的仍然会是相同的内容
例子:
docker start tf_test
docker attach tf_test
After running the above two sentences, it is considered to enter the container, and it will enter the (root) user of my container. The virtual environment created by docker has its own root user, so there is no need to worry about destroying the environment in the server. ~
3.3 Open multiple terminals in a single container
多个终端时:
首先使用docker ps显示运行的容器ID
docker exec -it contrainer_ID /bin/bash
After running the above command, the display is as follows, and it will not be displayed synchronously with the terminal opened under this container, which means that I can do other things in a single container. Enable multiple different terminals to be opened in a single container.
reference
1. Use Python virtual environment
2. How to open multiple terminals to enter the Docker container
3.docker-from entry to practice