1. What is Docker
Simply understood as a virtual machine mainly used on Linux, commonly used in the background.
Mirror: The mirror file of the system, which is a system
Container: a running virtual machine
Tar file: directly save the image as a tar file, which is a loadable intermediate file.
Dockfile: configuration file, build according to its content
Remote warehouse: The warehouse is a mirror file saved remotely
2. Process
First pull a basic image locally, and then you need to process it locally into the environment you need. At this time, you need to convert the image into a container operation, configure the environment you want and write the necessary scripts, and then convert the container again The completed image is submitted to the cloud, and the cloud runs the result according to the submitted image.
-
Pull a mirror image: You can find the connection from the following address: https://tianchi.aliyun.com/forum/postDetail?spm=5176.12282029.0.0.2dd1f33aTGlXoR&postId=67720
The FROM field in the Dockfile can fill in the mirroring address connection,
For example: registry.cn-shanghai.aliyuncs.com/tcc-public/pytorch:1.4-cuda10.1-py3
Or you can docker pull + connect to download the image
-
Run the image to get the container: docker run command
docker run -it -w working directory -v local directory: the directory mapped to the container --name container name imageid /bin/bash
- -it can generate terminal entry to enter
- -w specifies the working directory here. It is recommended to use / directly and specify as the root directory
- -v maps the local data directory, this is very important! !
- /bin/bash This can be the container always keeps the state
- -d run in the background
- -p Develop internal and external port mapping eg 80:80
-
Create the necessary scripts:
- run.sh which writes inference code, such as python infer.py
- infer.py inferencing code to generate the final prediction file
-
Convert the container to the image and submit:
- docker commit container id container name
- Upload the image to the warehouse through the command prompt on Alibaba Cloud
- Warehouse address + version number: ready to submit
-
Verification before submission:
- docker run -v /data:/tcdata your_image sh run.sh
3. Commonly used
docker ps to view the running container
docker images view image
Delete the container: docker rm -f container id
Delete mirror: docker rmi mirror id
Save the docker image: docker save/export image id> 1.tar
Load the docker image: docker load< 1.tar or cat docker/ubuntu.tar | docker import-test/ubuntu:v1
Exit the container: exit
Exit the container without closing the container Crtl+P+Q
View log: docker logs + container id
Stop/start the container: docker stop/start + container id
Load and get the image: docker pull ubuntu
When docker run -d is used, it means that the container is running in the background. If you want to enter the container, you need to use the command: docker exec + container id
Clean up all terminated containers: docker container prune
View the internal process of the container: docker top container name
Clean up all the images of None: docker image prune or docker rmi $(docker images -f “dangling=true” -q)
Find the mirror: docker search field
4. Dockfile
Dockerfile is a text file used to build a mirror. The text contains instructions and instructions for building a mirror.
- FROM + connection: build mirror
- RUN + command: Command executed eg: RUN ['sh','run.sh']
5. Nvidia-docker
nvidia-docker installation method:
sudo usermod -aG docker pdluser
curl https://get.docker.com | sh
sudo systemctl start docker && sudo systemctl enable docker
# 设置stable存储库和GPG密钥:
distribution=$(. /etc/os-release;echo $ID$VERSION_ID)
curl -s -L https://nvidia.github.io/nvidia-docker/gpgkey | sudo apt-key add -
curl -s -L https://nvidia.github.io/nvidia-docker/$distribution/nvidia-docker.list | sudo tee /etc/apt/sources.list.d/nvidia-docker.list
# 要访问experimental诸如WSL上的CUDA或A100上的新MIG功能之类的功能,您可能需要将experimental分支添加到存储库列表中.
# 可加可不加
curl -s -L https://nvidia.github.io/nvidia-container-runtime/experimental/$distribution/nvidia-container-runtime.list | sudo tee /etc/apt/sources.list.d/nvidia-container-runtime.list
# nvidia-docker2更新软件包清单后,安装软件包(和依赖项):
sudo apt-get update
sudo apt-get install -y nvidia-docker2
# 设置默认运行时后,重新启动Docker守护程序以完成安装:
sudo systemctl restart docker