我想在Dockerfile RUN命令中添加打印机,所以这是我的Dockerfile
FROM dassh/eline:base
MAINTAINER dassh
# start cups service is necessary to run lpadmin command
RUN service cups start && lpadmin -p VLM2601 -v EleanBackend:/tmp -m
VLM2601_gdi.ppd -E && echo done
生成过程
docker build -t dassh/eline .
Sending build context to Docker daemon 722.9kB
Step 1/3 : FROM dassh/eline:base
---> 712dce8cd557
Step 2/3 : MAINTAINER dassh
---> Running in 2f3f5f80b665
Removing intermediate container 2f3f5f80b665
---> 2b53b81d6ff4
Step 3/3 : RUN service cups start && lpadmin -p VLM2601 -v EleanBackend:/tmp -m VLM2601_gdi.ppd -E && echo done
---> Running in f176fbdf765e
* Starting Common Unix Printing System cupsd
...done.
done
Removing intermediate container f176fbdf765e
---> e229e278b085
Successfully built e229e278b085
Successfully tagged dassh/eline:latest
构建成功,没有任何错误。但是,当我使用该图像启动容器时,发现未添加打印机。
dassh@ubuntu:~$ docker run -itd dassh/eline /bin/bash
a8785057e71a598cd391f355848819295fef8e311090f70cbae95ca5360856c2
dassh@ubuntu:~$ docker cp ~/123.pdf a8:/
dassh@ubuntu:~$ docker attach a8
root@a8785057e71a:/pdf_to_prn#
root@a8785057e71a:/pdf_to_prn# service cups start
* Starting Common Unix Printing System cupsd [ OK ]
root@a8785057e71a:/pdf_to_prn# lp -o fit-to-page -o media=A4 -d VLM2601 /123.pdf
lp: The printer or class does not exist.
该命令返回一个打印机不存在的错误,但是当我在容器中手动执行添加打印机命令并再次运行lp命令时,一切都很好。
root@a8785057e71a:/pdf_to_prn# lpadmin -p VLM2601 -v EleanBackend:/tmp -m VLM2601_gdi.ppd -E
root@a8785057e71a:/pdf_to_prn# lp -o fit-to-page -o media=A4 -d VLM2601 /123.pdf
request id is VLM2601-1 (1 file(s))
因此,我的添加打印机命令没有问题。那到底是怎么回事?
最佳答案
该问题是由使用lpadmin
创建打印机引起的。
/etc/cups/printers.conf
获取打印机。 lpadmin
添加打印机将生成或更新/etc/cups/printers.conf
文件。 Dockerfile在生成文件
/etc/cups/printers.conf
之前完成此步骤。关于docker - Dockerfile运行lpadmin以添加无法在构建镜像中运行的打印机吗?,我们在Stack Overflow上找到一个类似的问题:https://stackoverflow.com/questions/49503382/