Docker學(xué)習(xí)實(shí)踐1-使用dockerfile構(gòu)建鏡像

針對(duì)開(kāi)源網(wǎng)絡(luò)打印機(jī)軟件CUPS的容器化實(shí)踐

創(chuàng)建一個(gè)目錄搁胆,并在目錄內(nèi)建立一個(gè)文件名為Dockerfile的文件和文件名為cupsd.conf的配置文件

Dockerfile

#使用原始鏡像
FROM centos:6
#作者
MAINTAINER shark1985
#使用阿里云yum源
RUN curl -o /etc/yum.repos.d/CentOS-Base.repo http://mirrors.aliyun.com/repo/Centos-6.repo && yum makecache
#安裝cups及組件
RUN yum -y install cups cups-libs
#備份原始配置文件
RUN mv /etc/cups/cupsd.conf /etc/cups/cupsd.conf.bak
#將cupsd.conf文件復(fù)制到配置目錄
COPY cupsd.conf /etc/cups/
#開(kāi)放631端口
EXPOSE 631
#運(yùn)行cups服務(wù)
CMD ["cupsd"]

cupsd.conf

  • 其中修改了"Listen *:631",允許任何地址訪問(wèn)
  • 如下增加"Allow all"配置
    Restrict access to the server...
    <Location />
    Order allow,deny
    Allow all
    </Location>

Restrict access to the admin pages...
<Location /admin>
Order allow,deny
Allow all
</Location>

Restrict access to configuration files...
<Location /admin/conf>
AuthType Default
Require user @SYSTEM
Order allow,deny
Allow all
</Location>

cupsd.conf文件內(nèi)容

MaxLogSize 0
#
# "$Id: cupsd.conf.in 8805 2009-08-31 16:34:06Z mike $"
#
# Sample configuration file for the CUPS scheduler.  See "man cupsd.conf" for a
# complete description of this file.
#

# Log general information in error_log - change "warn" to "debug"
# for troubleshooting...
LogLevel warn

# Administrator user group...
SystemGroup sys root


# Only listen for connections from the local machine.
Listen *:631
Listen /var/run/cups/cups.sock

# Show shared printers on the local network.
Browsing On
BrowseOrder allow,deny
BrowseAllow all
BrowseLocalProtocols CUPS dnssd

# Default authentication type, when authentication is required...
DefaultAuthType Basic

# Restrict access to the server...
<Location />
  Order allow,deny
  Allow all
</Location>

# Restrict access to the admin pages...
<Location /admin>
  Order allow,deny
  Allow all
</Location>

# Restrict access to configuration files...
<Location /admin/conf>
  AuthType Default
  Require user @SYSTEM
  Order allow,deny
  Allow all
</Location>

# Set the default printer/job policies...
<Policy default>
  # Job-related operations must be done by the owner or an administrator...
  <Limit Send-Document Send-URI Hold-Job Release-Job Restart-Job Purge-Jobs Set-Job-Attributes Create-Job-Subscription Renew-Subscription Cancel-Subscription Get-Notifications Reprocess-Job Cancel-Current-Job Suspend-Current-Job Resume-Job CUPS-Move-Job CUPS-Get-Document>
    Require user @OWNER @SYSTEM
    Order deny,allow
  </Limit>

  # All administration operations require an administrator to authenticate...
  <Limit CUPS-Add-Modify-Printer CUPS-Delete-Printer CUPS-Add-Modify-Class CUPS-Delete-Class CUPS-Set-Default CUPS-Get-Devices>
    AuthType Default
    Require user @SYSTEM
    Order deny,allow
  </Limit>

  # All printer operations require a printer operator to authenticate...
  <Limit Pause-Printer Resume-Printer Enable-Printer Disable-Printer Pause-Printer-After-Current-Job Hold-New-Jobs Release-Held-New-Jobs Deactivate-Printer Activate-Printer Restart-Printer Shutdown-Printer Startup-Printer Promote-Job Schedule-Job-After CUPS-Accept-Jobs CUPS-Reject-Jobs>
    AuthType Default
    Require user @SYSTEM
    Order deny,allow
  </Limit>

  # Only the owner or an administrator can cancel or authenticate a job...
  <Limit Cancel-Job CUPS-Authenticate-Job>
    Require user @OWNER @SYSTEM
    Order deny,allow
  </Limit>

  <Limit All>
    Order deny,allow
  </Limit>
</Policy>

# Set the authenticated printer/job policies...
<Policy authenticated>
  # Job-related operations must be done by the owner or an administrator...
  <Limit Create-Job Print-Job Print-URI>
    AuthType Default
    Order deny,allow
  </Limit>

  <Limit Send-Document Send-URI Hold-Job Release-Job Restart-Job Purge-Jobs Set-Job-Attributes Create-Job-Subscription Renew-Subscription Cancel-Subscription Get-Notifications Reprocess-Job Cancel-Current-Job Suspend-Current-Job Resume-Job CUPS-Move-Job CUPS-Get-Document>
    AuthType Default
    Require user @OWNER @SYSTEM
    Order deny,allow
  </Limit>

  # All administration operations require an administrator to authenticate...
  <Limit CUPS-Add-Modify-Printer CUPS-Delete-Printer CUPS-Add-Modify-Class CUPS-Delete-Class CUPS-Set-Default>
    AuthType Default
    Require user @SYSTEM
    Order deny,allow
  </Limit>

  # All printer operations require a printer operator to authenticate...
  <Limit Pause-Printer Resume-Printer Enable-Printer Disable-Printer Pause-Printer-After-Current-Job Hold-New-Jobs Release-Held-New-Jobs Deactivate-Printer Activate-Printer Restart-Printer Shutdown-Printer Startup-Printer Promote-Job Schedule-Job-After CUPS-Accept-Jobs CUPS-Reject-Jobs>
    AuthType Default
    Require user @SYSTEM
    Order deny,allow
  </Limit>

  # Only the owner or an administrator can cancel or authenticate a job...
  <Limit Cancel-Job CUPS-Authenticate-Job>
    AuthType Default
    Require user @OWNER @SYSTEM
    Order deny,allow
  </Limit>

  <Limit All>
    Order deny,allow
  </Limit>
</Policy>

構(gòu)建鏡像

docker build -t office-cups-centos6 .

構(gòu)建過(guò)程

Sending build context to Docker daemon  6.656kB
Step 1/8 : FROM centos:6
 ---> d0957ffdf8a2
Step 2/8 : MAINTAINER shark1985
 ---> Using cache
 ---> 27ecd3caf516
Step 3/8 : RUN curl -o /etc/yum.repos.d/CentOS-Base.repo http://mirrors.aliyun.com/repo/Centos-6.repo && yum makecache
 ---> Using cache
 ---> b1c6f3ba74d5
Step 4/8 : RUN yum -y install cups cups-libs
 ---> Using cache
 ---> 48e62c3cb9c7
Step 5/8 : RUN mv /etc/cups/cupsd.conf /etc/cups/cupsd.conf.bak
 ---> Running in b916430865f1
Removing intermediate container b916430865f1
 ---> 0bec467158d6
Step 6/8 : COPY cupsd.conf /etc/cups/
 ---> 16187084007f
Step 7/8 : EXPOSE 631
 ---> Running in e9644f736601
Removing intermediate container e9644f736601
 ---> 3322999c070b
Step 8/8 : CMD ["cupsd"]
 ---> Running in 9eec5c9fc7dd
Removing intermediate container 9eec5c9fc7dd
 ---> 354c91defd47
Successfully built 354c91defd47
Successfully tagged office-cups-centos6:latest

查看鏡像

docker images
REPOSITORY                   TAG                 IMAGE ID            CREATED             SIZE
office-cups-centos6          latest              354c91defd47        About an hour ago   487MB

使用鏡像運(yùn)行容器

docker run -d -p 631:631  office-cups:latest

docker ps -a
CONTAINER ID        IMAGE                        COMMAND                  CREATED             STATUS                      PORTS                                          NAMES
e63fc4ae54cc        office-cups-centos6:latest   "cupsd"                  About an hour ago   Up About an hour            0.0.0.0:631->631/tcp

進(jìn)入容器為root添加密碼色洞,才能管理CUPS

docker exec -it e63fc4ae54cc /bin/bash
[root@e63fc4ae54cc /]# passwd

通過(guò)https訪問(wèn)CUPS管理頁(yè)面
https://ip:631/admin
使用前面的root賬號(hào)和密碼登錄

image.png
最后編輯于
?著作權(quán)歸作者所有,轉(zhuǎn)載或內(nèi)容合作請(qǐng)聯(lián)系作者
  • 序言:七十年代末,一起剝皮案震驚了整個(gè)濱河市纽竣,隨后出現(xiàn)的幾起案子奕坟,更是在濱河造成了極大的恐慌扒怖,老刑警劉巖疗认,帶你破解...
    沈念sama閱讀 221,635評(píng)論 6 515
  • 序言:濱河連續(xù)發(fā)生了三起死亡事件,死亡現(xiàn)場(chǎng)離奇詭異伏钠,居然都是意外死亡横漏,警方通過(guò)查閱死者的電腦和手機(jī),發(fā)現(xiàn)死者居然都...
    沈念sama閱讀 94,543評(píng)論 3 399
  • 文/潘曉璐 我一進(jìn)店門(mén)熟掂,熙熙樓的掌柜王于貴愁眉苦臉地迎上來(lái)缎浇,“玉大人,你說(shuō)我怎么就攤上這事赴肚∷囟澹” “怎么了?”我有些...
    開(kāi)封第一講書(shū)人閱讀 168,083評(píng)論 0 360
  • 文/不壞的土叔 我叫張陵誉券,是天一觀的道長(zhǎng)指厌。 經(jīng)常有香客問(wèn)我,道長(zhǎng)踊跟,這世上最難降的妖魔是什么踩验? 我笑而不...
    開(kāi)封第一講書(shū)人閱讀 59,640評(píng)論 1 296
  • 正文 為了忘掉前任,我火速辦了婚禮商玫,結(jié)果婚禮上箕憾,老公的妹妹穿的比我還像新娘。我一直安慰自己拳昌,他們只是感情好袭异,可當(dāng)我...
    茶點(diǎn)故事閱讀 68,640評(píng)論 6 397
  • 文/花漫 我一把揭開(kāi)白布。 她就那樣靜靜地躺著炬藤,像睡著了一般御铃。 火紅的嫁衣襯著肌膚如雪。 梳的紋絲不亂的頭發(fā)上刻像,一...
    開(kāi)封第一講書(shū)人閱讀 52,262評(píng)論 1 308
  • 那天畅买,我揣著相機(jī)與錄音,去河邊找鬼细睡。 笑死谷羞,一個(gè)胖子當(dāng)著我的面吹牛,可吹牛的內(nèi)容都是我干的。 我是一名探鬼主播湃缎,決...
    沈念sama閱讀 40,833評(píng)論 3 421
  • 文/蒼蘭香墨 我猛地睜開(kāi)眼犀填,長(zhǎng)吁一口氣:“原來(lái)是場(chǎng)噩夢(mèng)啊……” “哼!你這毒婦竟也來(lái)了嗓违?” 一聲冷哼從身側(cè)響起九巡,我...
    開(kāi)封第一講書(shū)人閱讀 39,736評(píng)論 0 276
  • 序言:老撾萬(wàn)榮一對(duì)情侶失蹤,失蹤者是張志新(化名)和其女友劉穎蹂季,沒(méi)想到半個(gè)月后冕广,有當(dāng)?shù)厝嗽跇?shù)林里發(fā)現(xiàn)了一具尸體,經(jīng)...
    沈念sama閱讀 46,280評(píng)論 1 319
  • 正文 獨(dú)居荒郊野嶺守林人離奇死亡偿洁,尸身上長(zhǎng)有42處帶血的膿包…… 初始之章·張勛 以下內(nèi)容為張勛視角 年9月15日...
    茶點(diǎn)故事閱讀 38,369評(píng)論 3 340
  • 正文 我和宋清朗相戀三年逮诲,在試婚紗的時(shí)候發(fā)現(xiàn)自己被綠了剪芍。 大學(xué)時(shí)的朋友給我發(fā)了我未婚夫和他白月光在一起吃飯的照片赛不。...
    茶點(diǎn)故事閱讀 40,503評(píng)論 1 352
  • 序言:一個(gè)原本活蹦亂跳的男人離奇死亡疗垛,死狀恐怖,靈堂內(nèi)的尸體忽然破棺而出宾肺,到底是詐尸還是另有隱情溯饵,我是刑警寧澤,帶...
    沈念sama閱讀 36,185評(píng)論 5 350
  • 正文 年R本政府宣布锨用,位于F島的核電站丰刊,受9級(jí)特大地震影響,放射性物質(zhì)發(fā)生泄漏黔酥。R本人自食惡果不足惜藻三,卻給世界環(huán)境...
    茶點(diǎn)故事閱讀 41,870評(píng)論 3 333
  • 文/蒙蒙 一、第九天 我趴在偏房一處隱蔽的房頂上張望跪者。 院中可真熱鬧棵帽,春花似錦、人聲如沸渣玲。這莊子的主人今日做“春日...
    開(kāi)封第一講書(shū)人閱讀 32,340評(píng)論 0 24
  • 文/蒼蘭香墨 我抬頭看了看天上的太陽(yáng)忘衍。三九已至逾苫,卻和暖如春,著一層夾襖步出監(jiān)牢的瞬間枚钓,已是汗流浹背铅搓。 一陣腳步聲響...
    開(kāi)封第一講書(shū)人閱讀 33,460評(píng)論 1 272
  • 我被黑心中介騙來(lái)泰國(guó)打工, 沒(méi)想到剛下飛機(jī)就差點(diǎn)兒被人妖公主榨干…… 1. 我叫王不留搀捷,地道東北人星掰。 一個(gè)月前我還...
    沈念sama閱讀 48,909評(píng)論 3 376
  • 正文 我出身青樓多望,卻偏偏與公主長(zhǎng)得像,于是被迫代替她去往敵國(guó)和親氢烘。 傳聞我的和親對(duì)象是個(gè)殘疾皇子怀偷,可洞房花燭夜當(dāng)晚...
    茶點(diǎn)故事閱讀 45,512評(píng)論 2 359

推薦閱讀更多精彩內(nèi)容