针对打印服务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账号和密码登录
转载于:https://blog.51cto.com/talk1985/2404986