Docker in docker. Solve technical environment problems

reason

Many times we will use docker as environment control to ensure that the environment is consistent when the service is executed.
But sometimes we may need to perform services that require resources and environment at the same time.
For example: tensorflow inference
There are two ways to create a container from the container.

method 1

Connect Linux docker to the container
Insert picture description here

concept:

Send the Linux docker service directly into the container so that it can be called directly.

docker run hello-world -v /var/run/docker.sock:/var/run/docker.sock
Simple brute force solution.
If you want to change to cloud k8s subordinate service in the future, you will encounter problems

Method 2 Install docker on docker container

*This is installed in nvcr.io/nvidia/tensorflow:20.10-tf2-py3 as the base container to
Insert picture description here
install Docker
apt update
apt install docker.io

Install nvidia runtime

curl -s -L https://nvidia.github.io/nvidia-container-runtime/gpgkey | \
 apt-key add -
distribution=$(. /etc/os-release;echo $ID$VERSION_ID)
curl -s -L https://nvidia.github.io/nvidia-container-runtime/$distribution/nvidia-container-runtime.list | \
  tee /etc/apt/sources.list.d/nvidia-container-runtime.list
 
apt update

apt install nvidia-container-runtime

& Is the meaning of background execution, and the foreground can be called back through fg.

Adjust related settings
Because the container does not have systemctl, some parameters must be adjusted manually.
Modify in /etc/docker/daemon.json:

{
    
    
 "storage-driver":"vfs"
,"runtimes":{
    
    
        "nvidia":{
    
    
                "path":"nvidia-container-runtime",
                "runtimeArgs":[]
        }
  }
}

Because the hard disk format used in the container of vfs is different from the linux environment, it is necessary to adjust the
runtimes and the nvidia runtime cannot be installed automatically after the installation, and must be adjusted manually

Manually start the docker daemon

dockerd &

Whether the test environment is feasible
Test whether the internal container will run smoothly
docker run hello-world

Test whether the internal container can access gpu resource
docker run --runtime=nvidia nvcr.io/nvidia/tensorflow:20.10-tf2-py3 nvidia-smi

Guess you like

Origin blog.csdn.net/wlcs_6305/article/details/115009802