CentOS 7 docker 安裝筆記

先用下面指令進行安裝

# yum-config-manager – -add-repo https://download.docker.com/linux/centos/docker-ce.repo

# yum install -y docker-ce docker-ce-cli containerd.io

如果有安裝舊的版本,可以用下列指令清除一下

# yum remove -y docker docker-client docker-client-latest docker-common docker-latest docker-latest-logrotate docker-logrotate docker-engine

由於我的環境在無網路的環境所以要使用 proxy ,參考官方網頁說用 17.07 之後的版本要改用下列的設定檔 ~/.docker/config.json 指定 proxy

{
“proxies” : {
“default” : {
“httpProxy” : “http://xxx.xxx.xxx.xxx:3128”,
“httpsProxy” : “http://xxx.xxx.xxx.xxx:3128”,
“ftpProxy” : “http://xxx.xxx.xxx.xxx:3128”,
“noProxy” : “*.liho.tw”
}
}

可是我設定了之後還是沒作用,於是用了下面的方法解決躲在 proxy 後的問題

# mkdir /etc/systemd/system/docker.service.d/
# vi /etc/systemd/system/docker.service.d/proxy.conf
[Service]
Environment=”HTTP_PROXY=http://xxx.xxx.xxx.xxx:3128″
Environment=”HTTPS_PROXY=http://xxx.xxx.xxx.xxx:3128″
Environment=”FTP_PROXY=http://xxx.xxx.xxx.xxx:3128″
# systemctl daemon-reload
# systemctl restart docker
# systemctl show docker – -property Environment

這樣就可以正常使用了

# docker login
Login with your Docker ID to push and pull images from Docker Hub. If you don’t have a Docker ID, head over to https://hub.docker.com to create one.
Username: xxxxxx
Password:
WARNING! Your password will be stored unencrypted in /root/.docker/config.json.
Configure a credential helper to remove this warning. See
https://docs.docker.com/engine/reference/commandline/login/#credentials-store

Login Succeeded

然後想要額外使用 nvidia docker

# cd /etc/yum.repos.d/
# wget https://nvidia.github.io/nvidia-docker/centos7/nvidia-docker.repo
# yum install -y nvidia-container-toolkit

測試一下是否有安裝成功

#### Test nvidia-smi with the latest official CUDA image
$ docker run – -gpus all nvidia/cuda:9.0-base nvidia-smi

# Start a GPU enabled container on two GPUs
$ docker run – -gpus 2 nvidia/cuda:9.0-base nvidia-smi

# Starting a GPU enabled container on specific GPUs
$ docker run – -gpus ‘”device=1,2″‘ nvidia/cuda:9.0-base nvidia-smi
$ docker run – -gpus ‘”device=UUID-ABCDEF,1″‘ nvidia/cuda:9.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:9.0-base nvidia-smi

列表已經下載的 images

# docker image ls
REPOSITORY TAG IMAGE ID CREATED SIZE
nvidia/cuda 9.0-base 1443caa429f9 3 weeks ago 137MB

docker 預設使用 images 的路徑是 /var/lib/docker 如果當時的 / 割太小就要留意了

可以把 host 的路徑導入 container 裡面執行,參考下面指令

# docker run -v `pwd`:`pwd` -w `pwd` -i -t – -gpus all nvidia/cuda:9.0-base ./xxxxx

下載額外要用的 image,可以先到 nvidia docker hub 參考他們有什麼

# docker pull nvidia/cuda:10.1-runtime-centos7

收工 繼續學習

Leave a Reply

Your email address will not be published. Required fields are marked *

 

This site uses Akismet to reduce spam. Learn how your comment data is processed.