在 docker 上运行 Cups

问题描述 投票:0回答:1

经过多次尝试/错误和在线浏览后,我最近能够在 docker 中运行

cups
。我在运行
supervisord
的单独映像上运行它,访问容器时,我可以运行
lpstat
并可以验证
cups
实际上正在运行。 Docker 在我的计算机上本地运行,而不是在服务器中,并且暂时会像这样运行。

现在,我正在尝试弄清楚如何添加我的打印机。我正在使用标签打印机(`Epson TM-T20III),它通过 USB 连接到我的 Mac。

当我尝试访问

cups
UI (http://localhost:631/printers/) 时,我不是从 docker 访问,而是从我的计算机访问。

我尝试将

Listen *:631
添加到我的
cupsd.conf
但在尝试访问
http://0.0.0.0:631/
时,我收到了错误的请求错误。以前是
Listen 0.0.0.0:631
,但现在变成了
This site can't be reached

我尝试将端口

632
映射到 Docker 中使用的
631
但不起作用。

这是我的

Dockerfile

FROM php:8.1.12-fpm

ARG uid=1000
ARG user=inigomontoya

RUN apt-get update && apt-get install -y \
    libpng-dev \
    libonig-dev \
    libxml2-dev \
    libzip-dev \
    git \
    curl \
    zip \
    unzip \
    supervisor \
    cups \
    cups-pdf

# Install and enable xDebug
RUN pecl install xdebug \
    && docker-php-ext-enable xdebug

RUN apt-get clean && rm -rf /var/lib/apt/lists/*

# Install php modules required by laravel.
RUN docker-php-ext-install pdo_mysql mbstring exif pcntl bcmath gd zip

# Create system user to run Composer and Artisan commands.
RUN useradd -G www-data,root -u $uid -d /home/$user $user
RUN mkdir -p /home/$user/.composer && \
    chown -R $user:$user /home/$user

# Install composer
COPY --from=composer:latest /usr/bin/composer /usr/bin/composer

# Create directory for supervisor logs
RUN mkdir -p "/etc/supervisor/logs" && chmod -R 775 "/etc/supervisor/logs"

# Set working directory
WORKDIR /var/www

# Copy supervisor config files
COPY ./docker/config/supervisor/supervisord.conf /etc/supervisor/supervisord.conf

COPY cupsd.conf /etc/cups/cupsd.conf

USER $user

这是

docker-compose.yaml

version: "3.9"
services:
  app:
    build:
      context: ./
      dockerfile: Dockerfile
    image: dmc
    container_name: dmc-app
    restart: unless-stopped
    working_dir: /var/www/
    env_file:
      - ./.env.development
    depends_on:
      - db
      - nginx
    volumes:
      - ./:/var/www/
      - ./docker/php/conf.d/xdebug.ini:/usr/local/etc/php/conf.d/docker-php-ext-xdebug.ini
      - ./docker/php/conf.d/error_reporting.ini:/usr/local/etc/php/conf.d/error_reporting.ini
      - ./images:/public/images
    expose:
      - "9003"
      - "631"
    networks:
      - dmc-net

  nginx:
    image: nginx:1.23.2-alpine
    container_name: dmc-nginx
    restart: unless-stopped
    ports:
      - "8000:80"
    volumes:
      - ./:/var/www
      - ./docker-compose/nginx:/etc/nginx/conf.d
    networks:
      - dmc-net

  supervisor:
    build: .
    container_name: dmc-supervisor
    command: /usr/bin/supervisord
    restart: unless-stopped
    depends_on:
      - app
      - nginx
      - db
    volumes:
      - ./:/var/www/
      - ./docker/config/supervisor/supervisord.conf:/etc/supervisor/supervisord.conf
    expose:
      - "632:631"
    networks:
      - dmc-net

这是

cupsd.conf
文件:

DefaultEncryption Never
LogLevel warn
PageLogFormat
Port 631
Listen 0.0.0.0:631
Browsing On
BrowseLocalProtocols dnssd
DefaultAuthType Basic
WebInterface yes

<Location />
  Order allow,deny
  Allow all
</Location>

<Location /admin>
  Order allow,deny
  Allow All
</Location>

<Location /admin/conf>
  AuthType Default
  Require user @SYSTEM
  Order allow,deny
</Location>
<Location /admin/log>
  AuthType Default
  Require user @SYSTEM
  Order allow,deny
</Location>
<Policy default>
  JobPrivateAccess default
  JobPrivateValues default
  SubscriptionPrivateAccess default
  SubscriptionPrivateValues default
  <Limit Create-Job Print-Job Print-URI Validate-Job>
    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 Cancel-My-Jobs Close-Job CUPS-Move-Job>
    Require user @OWNER @SYSTEM
    Order deny,allow
  </Limit>
  <Limit CUPS-Get-Document>
    AuthType Default
    Require user @OWNER @SYSTEM
    Order deny,allow
  </Limit>
  <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>
  <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 Cancel-Jobs CUPS-Accept-Jobs CUPS-Reject-Jobs>
    AuthType Default
    Require user @AUTHKEY(system.print.operator) @admin @lpadmin
    Order deny,allow
  </Limit>
  <Limit Cancel-Job CUPS-Authenticate-Job>
    Require user @OWNER @AUTHKEY(system.print.operator) @admin @lpadmin
    Order deny,allow
  </Limit>
  <Limit All>
    Order deny,allow
  </Limit>
</Policy>
<Policy authenticated>
  JobPrivateAccess default
  JobPrivateValues default
  SubscriptionPrivateAccess default
  SubscriptionPrivateValues default
  <Limit Create-Job Print-Job Print-URI Validate-Job>
    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 Cancel-My-Jobs Close-Job CUPS-Move-Job CUPS-Get-Document>
    AuthType Default
    Require user @OWNER @SYSTEM
    Order deny,allow
  </Limit>
  <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>
  <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 Cancel-Jobs CUPS-Accept-Jobs CUPS-Reject-Jobs>
    AuthType Default
    Require user @AUTHKEY(system.print.operator) @admin @lpadmin
    Order deny,allow
  </Limit>
  <Limit Cancel-Job CUPS-Authenticate-Job>
    AuthType Default
    Require user @OWNER @AUTHKEY(system.print.operator) @admin @lpadmin
    Order deny,allow
  </Limit>
  <Limit All>
    Order deny,allow
  </Limit>
</Policy>
<Policy kerberos>
  JobPrivateAccess default
  JobPrivateValues default
  SubscriptionPrivateAccess default
  SubscriptionPrivateValues default
  <Limit Create-Job Print-Job Print-URI Validate-Job>
    AuthType Negotiate
    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 Cancel-My-Jobs Close-Job CUPS-Move-Job CUPS-Get-Document>
    AuthType Negotiate
    Require user @OWNER @SYSTEM
    Order deny,allow
  </Limit>
  <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>
  <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 Cancel-Jobs CUPS-Accept-Jobs CUPS-Reject-Jobs>
    AuthType Default
    Require user @AUTHKEY(system.print.operator) @admin @lpadmin
    Order deny,allow
  </Limit>
  <Limit Cancel-Job CUPS-Authenticate-Job>
    AuthType Negotiate
    Require user @OWNER @AUTHKEY(system.print.operator) @admin @lpadmin
    Order deny,allow
  </Limit>
  <Limit All>
    Order deny,allow
  </Limit>
</Policy>
PageLogFormat
PageLogFormat
PageLogFormat

这是

supervisord.conf
文件以防万一:

[supervisord]
logfile=/etc/supervisor/logs/supervisord.log ; main log file; default $CWD/supervisord.log
logfile_maxbytes=5MB         ; max main logfile bytes b4 rotation; default 50MB
logfile_backups=10           ; # of main logfile backups; 0 means none, default 10
loglevel=info                ; log level; default info; others: debug,warn,trace
pidfile=/tmp/supervisord.pid ; supervisord pidfile; default supervisord.pid
nodaemon=true                ; start in foreground if true; default false
minfds=1024                  ; min. avail startup file descriptors; default 1024
minprocs=200                 ; min. avail process descriptors;default 200

[supervisorctl]
serverurl=unix:///tmp/supervisor.sock ; use a unix:// URL  for a unix socket

[program:app-worker]
# user=root
process_name=%(program_name)s_%(process_num)02d
command=php /var/www/artisan queue:work --sleep=3 --tries=3
autostart=true
autorestart=true
stopasgroup=true
killasgroup=true
numprocs=1
redirect_stderr=true
stdout_logfile=/var/www/storage/logs/worker.log

[program:cups]
process_name=%(program_name)s_%(process_num)02d
command=/usr/sbin/cupsd -f
autostart=true
autorestart=true
stopasgroup=true
killasgroup=true
numprocs=1
redirect_stderr=true
stdout_logfile=/var/www/storage/logs/cups.log

有一些东西我不太明白,从我的

app
容器(那是我的后端代码所在的位置)我正在运行内部使用
lpstat
(我正在使用 PHP 库)的 print 命令,但是这个命令安装在不同的容器中(运行
supervisor
的容器),我怎样才能完成这项工作?

谢谢。

linux docker docker-compose printing cups
1个回答
0
投票

问题

这对你没有任何帮助。

    expose:
      - "632:631"

如文档所述 文档

公开端口而不将它们发布到主机 - 它们只能由链接的服务访问。只能指定内部端口。

解决方案

将端口暴露给主机需要做的是:

    ports:
      - "6311:631"

这使您可以访问

http://localhost:6311
的服务。但是,这给出了
Bad Request
,您需要更新您的
cupsd.conf
以包含此行:

ServerAlias *

请注意,这可能不足以实际使用杯子。使用这个现成的镜像可能会更好 https://hub.docker.com/r/olbat/cupsd,但即使你不这样做,你可能至少需要按照他们指示的去做和挂载 dbus像这样的卷:

/var/run/dbus:/var/run/dbus 

© www.soinside.com 2019 - 2024. All rights reserved.