在 Azure 上使用 Docker 執行 Mono

張善友的部落格發表於2014-12-17

Docker 是最近相當熱門的一個名詞,它是一個基於 Linux Container 的輕量化的虛擬技術,而微軟也相當積極與 Docker 合作,在 Azure 上支援這個火熱的技術,並且提供簡單的方式來建立 Docker Host,本文將會介紹如何在 Azure 上使用 Docker執行DockerMono映象。

Docker 簡介

Docker 是一個開源的專案,主要的特點是能將應用程式包裝在一個 LXC (Linux Container) 容器中,當這些應用被包裝進容器後,部署、遷移都變得更為簡單。與傳統的虛擬化技術相比,虛擬機器需要安裝作業系統才能執行應用程式,而 Container 則不需要安裝作業系統就能執行應用程式。Container 技術是一種在 作業系統內的 Kernel 層所打造虛擬執行環境,所以 Container 彼此之間共享了 Host OS 的 Kernel,但通過namespace 區分來達到隔離每個容器的目的。

本文並不會針對 Docker 這個技術做深入的介紹,主要著重在 Azure 對於 Docker 所提供的支援做介紹,詳細瞭解可以參考 Docker 入門教程。

在 Azure 上建立 Docker Host

Docker 可以執行在 Linux 作業系統之下,所以如果要在 Azure 上使用 Docker,您也可以自行建立一個Linux VM,並在上面安裝 並執行Docker Deamon 。而微軟在正式宣佈與 Docker 密切合作後,推出了對 Docker 的直接支援,CentOS 7 中 Docker 的安裝

Docker 軟體包已經包括在預設的 CentOS-Extras 軟體源裡。因此想要安裝 docker,只需要執行下面的 yum 命令:

[root@Mono ~]# yum install docker

啟動 Docker 服務

[root@ Mono ~]# systemctl start docker.service
[root@ Mono ~]# systemctl enable docker.service

下載官方的 CentOS 映象到本地

[root@Mono ~]# docker pull centos
centos:latest: The image you are pulling has been verified
511136ea3c5a: Pull complete
5b12ef8fd570: Pull complete
34943839435d: Pull complete
Status: Downloaded newer image for centos:latest

確認 CentOS 映象已經被獲取:

[root@Mono ~]# docker images centos
REPOSITORY TAG IMAGE ID CREATED VIRTUAL SIZE
centos latest 34943839435d 13 days ago 224 MB

執行一個 Docker 容器:

[root@Mono ~]# docker run -i -t centos /bin/bash
[root@5d841f64f6f0 /]# ls /etc
BUILDTIME group nsswitch.conf rpm
DIR_COLORS group- openldap sasl2
DIR_COLORS.256color gshadow opt securetty
DIR_COLORS.lightbgcolor gshadow- os-release security
GREP_COLORS gss pam.d selinux
X11 host.conf passwd services
aliases hostname passwd- shadow
alternatives hosts pkcs11 shadow-
bash_completion.d hosts.allow pki shells
bashrc hosts.deny pm skel
binfmt.d init.d popt.d ssl
centos-release inputrc prelink.conf.d sysconfig
chkconfig.d iproute2 printcap sysctl.d
cron.daily issue profile system-release
cron.hourly issue.net profile.d system-release-cpe
csh.cshrc krb5.conf protocols systemd
csh.login ld.so.conf rc.d terminfo
dbus-1 ld.so.conf.d rc0.d tmpfiles.d
default libaudit.conf rc1.d udev
dracut.conf.d libuser.conf rc2.d virc
environment localtime rc3.d xdg
exports login.defs rc4.d xinetd.d
filesystems logrotate.d rc5.d yum
fstab magic rc6.d yum.conf
gcrypt modules-load.d redhat-release yum.repos.d
gnupg motd resolv.conf
groff mtab rpc

我們可以看到,CentOS 容器已經被啟動,並且我們得到了 bash 提示符。在 docker 命令中我們使用了 “-i 捕獲標準輸入輸出”和 “-t 分配一個終端或控制檯”選項。若要斷開與容器的連線,輸入 exit。

[root@5d841f64f6f0 /]# exit
Exit

我們還可以搜尋基於 mono的容器。 發現已經有非常多的mono容器,我們開始玩docker mono。

[root@Mono ~]# docker search mono
NAME DESCRIPTION STARS OFFICIAL AUTOMATED
mono Mono is an open source implementation of M... 24 [OK]
akoeplinger/mono-aspnetvnext Image containing everything needed to play... 14 [OK]
monokrome/wine 4 [OK]
monokrome/node 3 [OK]
friism/mono 2 [OK]
benhall/docker-mono Docker file at https://github.com/Ben Hall/... 2
devdiv/ubuntu-mono 1
nacyot/fsharp-mono 1 [OK]
caseyjbenko/docker-mono 1 [OK]
nacyot/csharp-mono 1 [OK]
rexm/mono-docker 1 [OK]
prozachj/docker-mono-aspnetvnext 1 [OK]
clarktlaugh/mono 0 [OK]
marcells/mono 0 [OK]
seif/docker-mono-fastcgi-nginx 0 [OK]
fghedin/docker-mono 0 [OK]
shaunol/mono-owin-webapi 0 [OK]
seif/mono-runit 0 [OK]
timefairy/debian-mono 0 [OK]
shaunol/learning-mono 0 [OK]
rmacdonaldsmith/docker-debian-mono-devel 0 [OK]
misakai/mono Mono and LLVM on Debian 0
bryanayers/centos7-mono-snapshot 0 [OK]
fghedin/docker-mono-hello 0 [OK]
acazau/docker-mono 0 [OK]
andmos/mono Baseimage for Mono-runtime. 0
eflab/mono 0
jbonhag/mono-hosting-wcf 0 [OK]
thachmai/mono-complete 0 [OK]
andrefernandes/docker-mono 0 [OK]
mikehadlow/ubuntu-monoxide-mono-devel 0 [OK]
allunite/mono-base Ubuntu with Mono base image 0
wimperdt/mono-in-docker 0 [OK]
ahmet/docker-mono-build 0 [OK]
pmcgrath/mono 0
allunite/buildimage-mono Drone.io build image for mono apps 0
tomrijntjes/monoculture 0 [OK]
pjvds/mono 0
basecrm/mono 0
monokrome/btsync 0 [OK]
basespace/mono 0
robzhu/mono 0
monokrome/zmq 0 [OK]
bowery/mono 0
wbonner/unity-mono 0
wayneo/mono 0
rwentzel/ubuntu-mono Ubuntu 13.04 with Mono 3.2.3 0
scottrudy/mono 0
haaf/mono-baseline A Mono 3.8 baseline with F# installed . So... 0
monokrome/minecraft 0 [OK]
bryanayers/centos7-mono3.10.0 0 [OK]
tilde/mono 0
junsuzuki/mono 0
virkokka/mono-fsharp Ubuntu 14.04 with mono and F# 0
pcherng/phasingapp-mono-dev 0
bryanayers/centos7-mono3.8.0 0 [OK]
monokrome/gitreceive 0 [OK]
kolektiv/mono 0
octohost/mono 0
leptonix/mono 0
monokrome/azure-cli 0 [OK]
monokrome/renderize 0 [OK]
monokrome/gitolite 0 [OK]
paulbrennan/mono 0
monokrome/sshd 0 [OK]
basespace/centos-mono 0
monokrome/nibbler 0 [OK]
saltosystems/mono-xsp4-app 0
clintonalee/centos6-mono 0
endeavour/nginx-mono 0
monokrome/chat 0 [OK]
armbuild/crosbymichael-mono 0
jpina/centos-mono 0
bjornno/mono-phonebook 0
pcherng/jellyfish-mono 0
petee/centos-mono 0
menziesbenwiles/test-mono 0
nyasara/azurepymono A base ubuntu image with Mono, Azure SDK f... 0 [OK]
allanlei/mono-fastcgi-server2 0
petee/centos-mono-2.10.2 0
nyasara/monobase Adds Azure SDK and IronPython to a mo no image 0
hack13/mono310 opensuse mono 3.10 0
originalsurfmex/monode development sandbox (uses 8080): node , exp... 0
jgarverick/monocent Linux image with Mono framework pre-i nstalled 0
pgrm/mono_baseimage 0
pcherng/puma00-14-07-09-mono 0
jgarverick/monodeb 0
azraelrabbit/monup mono opt for jexus web server 0 [OK]
afilimonov/hcci-solr 0 [OK]
afilimonov/docker-solr 0 [OK]
fireantik/fireantmonodocker 0 [OK]
monolive/centos 0
monofraps/centos65-base 0
callumelgrant/docker-mono-aspnetvnext 0 [OK]
seif/mono Debian based mono container using xam arin ... 0 [OK]
smartprocure/mono 0 [OK]
jamesottaway/mono Mono is an open source implementation of M... 0 [OK]
cuda/mono Mono latest release container based o n Ubu... 0 [OK]
crosbymichael/mono 0 [OK]
derekslager/mono 0 [OK]
shaunol/centos-mono 0 [OK]
matsprea/mono-aspnetvnext Repository with MONO and the Asp.Net vnext... 0 [OK]
djsell/mono 0 [OK]
andystanton/exec-mono 0 [OK]
ndelitski/mono 0 [OK]
[root@Mono ~]#

下載Mono的 docker映象

[root@Mono ~]# docker pull mono
mono:latest: The image you are pulling has been verified
f10807909bc5: Pull complete
f6fab3b798be: Pull complete
3c43ebb7883b: Pull complete
7a1f8e485667: Pull complete
a342319da8ea: Pull complete
3774d7ea06a6: Pull complete
9da8fc8d2ff5: Pull complete
511136ea3c5a: Already exists
Status: Downloaded newer image for mono:latest
[root@Mono ~]#

使用docker執行mono

[root@Mono ~]# docker run -i -t mono bash
)
root@66f9d4b4c73b:/# mono -V
Mono JIT compiler version 3.10.0 (tarball Wed Nov 5 12:50:04 UTC 2014)
Copyright (C) 2002-2014 Novell, Inc, Xamarin Inc and Contributors. www.mono-project.com
TLS: __thread
SIGSEGV: altstack
Notifications: epoll
Architecture: amd64
Disabled: none
Misc: softdebug
LLVM: supported, not enabled.
GC: sgen
root@66f9d4b4c73b:/#

相關文章