应用场景
- Docker中使用anaconda管理python环境
1. 创建容器并启动
junli@ubuntu16:~$ docker images
REPOSITORY TAG IMAGE ID CREATED SIZE
nvidia/cuda 8.0-cudnn6-devel-ubuntu16.04 d57da4f50cd1 10 months ago 2.01GB
junli@ubuntu16:~$
junli@ubuntu16:~$ nvidia-docker run -i -d --net GJLDockerNetBridge --ip 192.168.120.× --name anaconda -v /home/junli/GJLImages/anaconda/:/home/GJL/ nvidia/cuda:8.0-cudnn6-devel-ubuntu16.04 /bin/bash
9f717fd87a22defd49db02d4f1fc4114bf004a4845be57ccc85d0bce386da9dc
junli@ubuntu16:~$
junli@ubuntu16:~$ docker ps -a
CONTAINER ID IMAGE COMMAND CREATED STATUS PORTS NAMES
9f717fd87a22 nvidia/cuda:8.0-cudnn6-devel-ubuntu16.04 "/bin/bash" 8 seconds ago Up 6 seconds anaconda
junli@ubuntu16:~$
junli@ubuntu16:~$ docker exec -it anaconda /bin/bash
root@9f717fd87a22:/#
root@9f717fd87a22:/# nvcc -V
nvcc: NVIDIA (R) Cuda compiler driver
Copyright (c) 2005-2016 NVIDIA Corporation
Built on Tue_Jan_10_13:22:03_CST_2017
Cuda compilation tools, release 8.0, V8.0.61
root@9f717fd87a22:/# nvidia-smi
Thu Aug 4 05:38:18 2022
+-----------------------------------------------------------------------------+
| NVIDIA-SMI 450.57 Driver Version: 450.57 CUDA Version: 11.0 |
|-------------------------------+----------------------+----------------------+
| GPU Name Persistence-M| Bus-Id Disp.A | Volatile Uncorr. ECC |
| Fan Temp Perf Pwr:Usage/Cap| Memory-Usage | GPU-Util Compute M. |
| | | MIG M. |
|===============================+======================+======================|
| 0 GeForce 940MX Off | 00000000:3C:00.0 Off | N/A |
| N/A 40C P0 N/A / N/A | 0MiB / 2004MiB | 0% Default |
| | | N/A |
+-------------------------------+----------------------+----------------------+
+-----------------------------------------------------------------------------+
| Processes: |
| GPU GI CI PID Type Process name GPU Memory |
| ID ID Usage |
|=============================================================================|
| No running processes found |
+-----------------------------------------------------------------------------+
root@9f717fd87a22:/#
2. 下载并安装
## 在本地下载好,直接上传到docker
junli@ubuntu16:~$ docker cp /home/junli/下载/Anaconda2-4.4.0-Linux-x86_64.sh anaconda:/home/GJL/
junli@ubuntu16:~$ docker exec -it anaconda /bin/bash
root@edb904c9b7b7:/# cd /home/GJL
root@edb904c9b7b7:/home/GJL# bash Anaconda2-4.3.1-Linux-x86_64.sh
Welcome to Anaconda2 4.4.0 (by Continuum Analytics, Inc.)
In order to continue the installation process, please review the license
agreement.
Please, press ENTER to continue
>>>
===================================
Anaconda End User License Agreement
===================================
Copyright 2017, Continuum Analytics, Inc.
......此处省略
Do you approve the license terms? [yes|no]
>>> yes
Anaconda2 will now be installed into this location:
/root/anaconda2
- Press ENTER to confirm the location
- Press CTRL-C to abort the installation
- Or specify a different location below
[/root/anaconda2] >>>
PREFIX=/root/anaconda2
installing: python-2.7.13-0 ...
......此处省略
installation finished.
Do you wish the installer to prepend the Anaconda2 install location
to PATH in your /root/.bashrc ? [yes|no]
[no] >>> yes
Prepending PATH=/root/anaconda2/bin to PATH in /root/.bashrc
A backup will be made to: /root/.bashrc-anaconda2.bak
root@9f717fd87a22:/home/GJL# source /root/.bashrc
root@9f717fd87a22:/home/GJL# conda info
Current conda install:
platform : linux-64
conda version : 4.3.21
conda is private : False
conda-env version : 4.3.21
conda-build version : not installed
python version : 2.7.13.final.0
requests version : 2.14.2
root environment : /root/anaconda2 (writable)
default environment : /root/anaconda2
envs directories : /root/anaconda2/envs
/root/.conda/envs
package cache : /root/anaconda2/pkgs
/root/.conda/pkgs
channel URLs : https://repo.continuum.io/pkgs/free/linux-64
https://repo.continuum.io/pkgs/free/noarch
https://repo.continuum.io/pkgs/r/linux-64
https://repo.continuum.io/pkgs/r/noarch
https://repo.continuum.io/pkgs/pro/linux-64
https://repo.continuum.io/pkgs/pro/noarch
config file : None
netrc file : None
offline mode : False
user-agent : conda/4.3.21 requests/2.14.2 CPython/2.7.13 Linux/4.15.0-142-generic debian/stretch/sid glibc/2.23
UID:GID : 0:0
root@9f717fd87a22:/home/GJL# conda env list
# conda environments:
#
root * /root/anaconda2
root@9f717fd87a22:/home/GJL#
注意:安装成功后,需要 source /root/.bashrc 使文件生效。