Docker Installation and configuration (Docker 安装与配置)

Share:
## Outline - Docker installation - Nvidia-docker installation - Docker content management ## Docker Installation 1. Prepare: Ubuntu 16/18/19 ```sh ➜ uname -a Linux ×××× 5.3.0-51-generic #44~18.04.2-Ubuntu SMP Thu Apr 23 14:27:18 UTC 2020 x86_64 x86_64 x86_64 GNU/Linux ``` 1. Read https://docs.docker.com/engine/install/ubuntu/#install-using-the-repository 1. Update the `apt` package index and install packages to allow `apt` to use a repository over HTTPS: ```sh $ sudo apt-get update $ sudo apt-get install \ apt-transport-https \ ca-certificates \ curl \ gnupg-agent \ software-properties-common ``` 1. Add Docker’s official GPG key: ```sh curl -fsSL https://download.docker.com/linux/ubuntu/gpg | sudo apt-key add - ``` 1. Use the following command to set up the **stable** repository. To add the **nightly** or **test** repository, add the word `nightly` or `test` (or both) after the word `stable` in the commands below. [Learn about **nightly** and **test** channels](https://docs.docker.com/engine/install/). ```sh sudo add-apt-repository \ "deb [arch=amd64] https://download.docker.com/linux/ubuntu \ $(lsb_release -cs) \ stable" ``` 1. INSTALL DOCKER ENGINE ```sh $ sudo apt-get update $ sudo apt-get install docker-ce docker-ce-cli containerd.io ``` 1. Verify that Docker Engine is installed correctly by running the `hello-world` image. ```sh $ sudo docker run hello-world ``` 1. Check docker version ```sh ➜ sudo docker --version Docker version 19.03.8, build afacb8b7f0 ``` 1. Verify that Docker Engine is installed correctly by running the `hello-world` image. ```sh $ sudo docker run hello-world ``` 1. Reference - https://docs.docker.com/engine/install/ubuntu/#install-using-the-repository ## Post Installation ```sh sudo usermod -aG docker $USER ``` ## Nvidia-docker Installation ### Document You must install NVIDIA-DOCKER if you want to use NVIDIA GPU in docker - [nvidia-docker](https://github.com/NVIDIA/nvidia-docker) ### Prepare - NVIDIA Driver - Docker 19.03 > **Make sure you have installed the [NVIDIA driver](https://github.com/NVIDIA/nvidia-docker/wiki/Frequently-Asked-Questions#how-do-i-install-the-nvidia-driver) and Docker 19.03 for your Linux distribution** **Note that you do not need to install the CUDA toolkit on the host, but the driver needs to be installed** - Read https://github.com/NVIDIA/nvidia-docker ### Install on ubuntu 16/18/19 ```sh # Add the package repositories 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 sudo apt-get update && sudo apt-get install -y nvidia-container-toolkit sudo systemctl restart docker ``` ### Usage ```sh #### Test nvidia-smi with the latest official CUDA image docker run --gpus all nvidia/cuda:10.02-base nvidia-smi # Start a GPU enabled container on two GPUs docker run --gpus 2 nvidia/cuda:10.0-base nvidia-smi # Starting a GPU enabled container on specific GPUs docker run --gpus '"device=1,2"' nvidia/cuda:10.0-base nvidia-smi docker run --gpus '"device=UUID-ABCDEF,1"' nvidia/cuda:10.0-base nvidia-smi # Specifying a capability (graphics, compute, ...) for my container # Note this is rarely if ever used this way docker run --gpus all,capabilities=utility nvidia/cuda:10.0-base nvidia-smi ``` ## Docker content > The contents of `/var/lib/docker/`, including images, containers, volumes, and networks, are preserved. ### **How to move docker content to other disk?** 1. Description I have two disks, one is 256G and another is 1T. However, by default, the docker will be installed on the small disk. But I want to save my docker contents to the larger disk. 1. Solution - move `/var/lib/docker/` to disk 1T, e.g. ``mv /var/lib/docker newdisk`` - Add a soft link to point to the position, e.g. ``ln -s /var/lib/docker newdisk `` Example: ```sh ➜ /var/lib ll docker lrwxrwxrwx 1 root root 32 3月 23 19:02 docker -> /home/yubao/data/software/docker ```

No comments