1. 程式人生 > >製作docker 映象 Anaconda3 + tensorflow-gpu

製作docker 映象 Anaconda3 + tensorflow-gpu

實驗室伺服器為離線環境,不方便安裝各種環境,因此學習一下docker和singularity的映象製作。中間踩了不少坑,現在把過程記錄如下。

1. 安裝docker

1.1 docker 簡單介紹

Docker是一個開源的引擎,可以輕鬆的為任何應用建立一個輕量級的、可移植的、自給自足的容器。開發者在筆記本上編譯測試通過的容器可以批量地在生產環境中部署,包括VMs(虛擬機器)、bare metal、OpenStack 叢集和其他的基礎應用平臺。

Docker通常用於如下場景

  • web應用的自動化打包和釋出;
  • 自動化測試和持續整合、釋出;
  • 在服務型環境中部署和調整資料庫或其他的後臺應用;
  • 從頭編譯或者擴充套件現有的OpenShift或Cloud Foundry平臺來搭建自己的PaaS環境。

1.2 docker安裝

docker的安裝參考官網,這裡只是簡單的翻譯並總結了一下,docker分為dockerCE和dockerEE兩個版本,dockerCE針對個人使用者。因此這裡在Ubuntu16.04上安裝dockerCE,官網安裝教程連結[link]

https://docs.docker.com/install/

  1. 首先解除安裝掉系統中存在的舊版docker
 $ sudo apt-get remove docker docker-engine docker.io
  1. 升級apt
$ sudo apt-get update
  1. 安裝需要的前置包
$ sudo apt-get install \
    apt-transport-https \
    ca-certificates \
    curl \
    software-properties-common
  1. 新增docker官方GPG祕鑰
$ curl -fsSL https://download.docker.com/linux/ubuntu/gpg | sudo apt-key add -
  1. 安裝docker 也可選擇安裝其他版本的docker 具體命令見官網連結
$ sudo add-apt-repository \
   "deb [arch=amd64] https://download.docker.com/linux/ubuntu \
   $(lsb_release -cs) \
   stable"
$ sudo apt-get update
$ sudo apt-get install docker-ce
  1. 驗證docker安裝是否成功
$ sudo docker run hello-world

結果如下

Hello from Docker!
This message shows that your installation appears to be working correctly.

To generate this message, Docker took the following steps:
 1. The Docker client contacted the Docker daemon.
 2. The Docker daemon pulled the "hello-world" image from the Docker Hub.
    (amd64)
 3. The Docker daemon created a new container from that image which runs the
    executable that produces the output you are currently reading.
 4. The Docker daemon streamed that output to the Docker client, which sent it
    to your terminal.

To try something more ambitious, you can run an Ubuntu container with:
 $ docker run -it ubuntu bash

Share images, automate workflows, and more with a free Docker ID:
 https://hub.docker.com/

For more examples and ideas, visit:
 https://docs.docker.com/get-started/
  1. 非root使用者使用docker

安裝完成後如果當前使用者為非root使用者的話執行docker run hello-world命令會報錯Got permision denied ,為了避免每次都需要sudo執行docker,因此建立一個docker 使用者組 ,但是需要注意的是此時docker 使用者組等同於root賬戶,具體參考官網教程[link]https://docs.docker.com/install/linux/linux-postinstall/

$ sudo groupadd docker
$ sudo usermod -aG docker $USER
$ sudo systemctl restart docker

1.3 docker基本命令介紹

## 檢視docker版本和資訊
docker --version
docker version
docker info

##  執行docker容器
docker run hello-world

## 檢視docker映象
docker image ls

## 檢視docker容器
docker container ls
docker container ls --all
docker container ls -aq

參考連結