針對打印服務CUPS的容器化學習實踐。
- 需要創建一個目錄
- 在目錄內建立一個文件名爲Dockerfile的文件和文件名爲cupsd.conf的配置文件
Dockerfile
#使用原始鏡像
FROM centos:6
#作者
MAINTAINER TBS
#使用阿里雲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文件複製到配置目錄
COPY cupsd.conf /etc/cups/
#開放631端口
EXPOSE 631
#運行cups服務
CMD ["cupsd"]
配置文件cupsd.conf的修改
- 其中修改了"Listen *:631",允許任何地址訪問
- 如下增加"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>
構建鏡像
docker build -t office-cups-centos6 .
構建過程
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
使用鏡像運行容器
docker run -d -p 631:631 office-cups-centos6:latest
查看容器
docker ps -a |grep office-cups-centos6:latest
e63fc4ae54cc office-cups-centos6:latest "cupsd" 2 weeks ago Up 2 weeks 0.0.0.0:631->631/tcp
stoic_tesla
進入容器爲root添加密碼,才能管理CUPS
docker exec -it e63fc4ae54cc /bin/bash
[root@e63fc4ae54cc /]# passwd
通過https訪問CUPS管理頁面
https://ip:631/admin
使用前面的root賬號和密碼登錄