最近因為工作實驗環境需要, 需要安裝 docker 比較新的版本
寫了安裝小記還有 ansible playbook 檔案
OS: openSUSE Leap 42.1
套件安裝: docker 1.10.x 以上版本
(考慮實驗環境可能會測試 UCP 或是其他功能)
目前 docker 在 openSUSE Leap 42.1 官方版本為 1.9.x
套件版本查詢
之前進行套件查詢的時候都是使用 #zypper search 套件名稱
為了有更多的資訊, 以後會多一些參數
# zypper search -s --match-exact docker
Loading repository data...
Reading installed packages...
S | Name | Type | Version | Arch | Repository
--+--------+------------+------------+--------+--------------------------
| docker | package | 1.9.1-13.1 | x86_64 | openSUSE-Leap-42.1-Update
| docker | package | 1.9.1-10.1 | x86_64 | openSUSE-Leap-42.1-Update
| docker | package | 1.9.1-7.1 | x86_64 | openSUSE-Leap-42.1-Update
| docker | package | 1.9.0-4.1 | x86_64 | openSUSE-Leap-42.1-Update
| docker | package | 1.8.2-2.5 | x86_64 | openSUSE-Leap-42.1-Oss
大概就是加上 -s 以及 --match-exact 這兩個 option
- -s 顯示更多資訊, 但是沒有 -v 那麼多
- --match-exact 符合後面字串的套件
- 感覺效果像 --match-words ^docker$
因為要安裝非穩定版本以及想要批次安裝
初步嘗試想法
*使用 OneClickInstallCLI 搭配 .ymp 方式來安裝
相關檔案如下
但是目前 OneClickInstallCLI 不可以使用非互動方式安裝, 所以暫時作罷
目前作法
在 software.opensuse.org 搜尋 docker
點選 Virtualization:container
到專案頁面
點選 Repositories
這邊可以找到各個版本的 repositories 下載
我用的是 Leap 42.1 所以 點選 openSUSE_Leap 42.1 的連結
這邊可以看到 .repo 檔案
連結為
透過 zypper 指令來新增 repo, 加入 key 以及設定 refresh
# zypper --gpg-auto-import-keys addrepo -f http://download.opensuse.org/repositories/Virtualization:/containers/openSUSE_Leap_42.1/Virtualization:containers.repo
- --gpg-auto-import-keys 是自動匯入 repo的 key
- -f 為設定 auto refresh
透過 zypper repos 來查詢
# zypper repos
# | Alias | Name | Enabled | GPG Check | Refresh
---+---------------------------+------------------------------------------------+---------+-----------+--------
1 | Virtualization_containers | Virtualization:containers (openSUSE_Leap_42.1) | Yes | ( p) Yes | Yes
2 | openSUSE-42.1-0 | openSUSE-42.1-0 | No | ---- | No
# zypper -n install docker
Loading repository data...
Loading repository data...
Reading installed packages...
Resolving package dependencies...
The following 7 NEW packages are going to be installed:
bridge-utils docker docker-image-migrator git-core git-gui gitk perl-Error
The following recommended package was automatically selected:
docker-image-migrator
7 new packages to install.
Overall download size: 12.9 MiB. Already cached: 0 B. After the operation, additional 59.4 MiB will be used.
Continue? [y/n/? shows all options] (y): y
Retrieving package docker-image-migrator-1.0.2-7.1.x86_64
- -n 新版的zypper 使用 -n / --non-interactive 來避免互動
接下來準備啟動服務
確認目前狀態
# systemctl status docker
docker.service - Docker Application Container Engine
Loaded: loaded (/usr/lib/systemd/system/docker.service; disabled)
Active: inactive (dead)
Docs: http://docs.docker.com
啟動 docker
# systemctl start docker
確認目前狀態
# systemctl status docker
docker.service - Docker Application Container Engine
Loaded: loaded (/usr/lib/systemd/system/docker.service; disabled)
Active: active (running) since Thu 2016-03-31 11:00:58 CST; 2s ago
Docs: http://docs.docker.com
Main PID: 32272 (docker)
CGroup: /system.slice/docker.service
└─32272 /usr/bin/docker daemon -H fd://
設定開機啟動
確認目前狀態
# systemctl is-enabled docker
disabled
設定開機啟動
# systemctl enable docker
確認目前狀態
# systemctl is-enabled docker
enabled
-------------------------------------------------
另外寫了 ansible 的 playbook .yml 來進行安裝
檔案如下
# cat docker_unstable_openSUSELeap42.1_install.yml
---
#########################################################
# Install docker package and setup boot with unstable repo in openSUSE Leap 42.1
- name: use when conditionals and setup module (facts)
hosts: all
tasks:
# 使用 setup moudule 列出 OS 種類
- name: use setup module to list os distribution
# setup moudle 可以使用 filter 過濾相關內容
setup: filter=ansible_distribution
#########################################################
- name: Install docker and run service
# use [dockerUnstable] group to install
hosts: dockerUnstable
sudo: True
tasks:
# Add Virtualization:container project repo
- name: Add Virutalization:containers repo
shell: zypper --gpg-auto-import-keys addrepo -f http://download.opensuse.org/repositories/Virtualization:/containers/openSUSE_Leap_42.1/Virtualization:containers.repo
- name: Install docker with openSUSE Leap
zypper: name={{ item }}
with_items:
- docker
- curl
when: ansible_distribution == "openSUSE Leap"
#-------------------------------------------------------
- name: Set docker enable and run
service: name=docker state=started enabled=yes