在 debian 容器中静默安装 mysql-client

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

我正在尝试从

mysql-client
将软件包
node:latest
静默安装到
Dockerfile
Docker 容器中。

似乎

mysql-apt-config_0.8.24-1_all.deb
的安装没有完全按预期工作,因为我收到错误
Package 'mysql-client' has no installation candidate

如果我跳过命令

RUN dpkg -i mysql-apt-config_0.8.24-1_all.deb
和后续命令,那么在运行容器时,我可以手动执行
mysql-apt-config
的安装,并且安装
mysql-client
没有问题。

这是 Dockerfile:

FROM node:latest

WORKDIR /usr/src/app

COPY package*.json ./

RUN npm install

COPY . .

RUN apt-get update && apt-get install -y lsb-release debconf-utils
RUN bash -c "export DEBIAN_FRONTEND=noninteractive"
RUN bash -c "debconf-set-selections <<< 'mysql-apt-config        mysql-apt-config/repo-codename  select  buster'"
RUN bash -c "debconf-set-selections <<< 'mysql-apt-config        mysql-apt-config/select-server  select  mysql-8.0'"
RUN bash -c "debconf-set-selections <<< 'mysql-apt-config        mysql-apt-config/repo-distro    select  debian'"
RUN bash -c "debconf-set-selections <<< 'mysql-apt-config        mysql-apt-config/unsupported-platform   select  abort'"
RUN bash -c "debconf-set-selections <<< 'mysql-apt-config        mysql-apt-config/select-product select  Ok'"
RUN bash -c "debconf-set-selections <<< 'mysql-apt-config        mysql-apt-config/repo-url       string  http://repo.mysql.com/apt'"
RUN bash -c "debconf-set-selections <<< 'mysql-apt-config        mysql-apt-config/select-tools   select  '"
RUN bash -c "debconf-set-selections <<< 'mysql-apt-config        mysql-apt-config/tools-component        string  mysql-tools'"
RUN bash -c "debconf-set-selections <<< 'mysql-apt-config        mysql-apt-config/select-preview select  '"
RUN wget https://dev.mysql.com/get/mysql-apt-config_0.8.24-1_all.deb
RUN dpkg -i mysql-apt-config_0.8.24-1_all.deb
RUN apt-get update
RUN apt install mysql-client

EXPOSE 3000
CMD [ "node", "server.js" ]

输出:


#11 [ 7/20] RUN bash -c "export DEBIAN_FRONTEND=noninteractive"
#11 sha256:0e6e9ae0f16995a1079f7fa9d132220a03f7b7e344305aa764ab15d7579e8073
#11 DONE 0.5s
#12 [ 8/20] RUN bash -c "debconf-set-selections <<< 'mysql-apt-config        mysql-apt-config/repo-codename  select  buster'"
#12 sha256:b041cb76bbf9fb153df64390aca913f15e6619371420452329a358b65ebe56a2
#12 DONE 0.6s
#13 [ 9/20] RUN bash -c "debconf-set-selections <<< 'mysql-apt-config        mysql-apt-config/select-server  select  mysql-8.0'"
#13 sha256:f1196d055eddd42ad9d262ba15d9b03ef6652277c139df4324e469574c5da4da
#13 DONE 0.6s
#14 [10/20] RUN bash -c "debconf-set-selections <<< 'mysql-apt-config        mysql-apt-config/repo-distro    select  debian'"
#14 sha256:eb8f3a0e94a6795ed3e21996299fd4935f29915b4fe50d09f3455cc7f14034a5
#14 DONE 0.6s
#15 [11/20] RUN bash -c "debconf-set-selections <<< 'mysql-apt-config        mysql-apt-config/unsupported-platform   select  abort'"
#15 sha256:b4d1ce74843623ae9728419c9ae2c43d800e81f4dbc921d539ab1392f322fdff
#15 DONE 0.6s
#16 [12/20] RUN bash -c "debconf-set-selections <<< 'mysql-apt-config        mysql-apt-config/select-product select  Ok'"
#16 sha256:c74f42d918704c2ea0e647696353c13f94342d60ca9b04e96f951360492a0d77
#16 DONE 0.6s
#17 [13/20] RUN bash -c "debconf-set-selections <<< 'mysql-apt-config        mysql-apt-config/repo-url       string  http://repo.mysql.com/apt'"
#17 sha256:660bb6bac73b98b0d7abaf232aeddab1d62432e3a58ae61e373884ed713a2cf6
#17 DONE 0.6s
#18 [14/20] RUN bash -c "debconf-set-selections <<< 'mysql-apt-config        mysql-apt-config/select-tools   select  '"
#18 sha256:62c73d437f2d95cf9e08b2ceb3cb03df9bb77f5cfbb6a6942f71b78df9f8e003
#18 DONE 0.6s
#19 [15/20] RUN bash -c "debconf-set-selections <<< 'mysql-apt-config        mysql-apt-config/tools-component        string  mysql-tools'"
#19 sha256:7d776e25fb8a24ffc0b52e14b963eadbeabece41c68435026f1b9b11864a9293
#19 DONE 0.6s
#20 [16/20] RUN bash -c "debconf-set-selections <<< 'mysql-apt-config        mysql-apt-config/select-preview select  '"
#20 sha256:cb494cd0ea4ab8457610b8d39dbf80cd7825769db6127b798c259191715b8942
#20 DONE 0.5s
#21 [17/20] RUN wget https://dev.mysql.com/get/mysql-apt-config_0.8.24-1_all.deb
#21 sha256:e7549acd0454720f085a85c8e52d1a1d26a026d98f49ea94002e83e64eca64e2
#21 0.522 --2023-03-27 14:05:30--  https://dev.mysql.com/get/mysql-apt-config_0.8.24-1_all.deb
#21 0.527 Resolving dev.mysql.com (dev.mysql.com)... 184.25.152.140, 2a02:26f0:2b00:387::2e31, 2a02:26f0:2b00:3a2::2e31
#21 0.564 Connecting to dev.mysql.com (dev.mysql.com)|184.25.152.140|:443... connected.
#21 0.600 HTTP request sent, awaiting response... 302 Moved Temporarily
#21 0.775 Location: https://repo.mysql.com//mysql-apt-config_0.8.24-1_all.deb [following]
#21 0.775 --2023-03-27 14:05:31--  https://repo.mysql.com//mysql-apt-config_0.8.24-1_all.deb
#21 0.775 Resolving repo.mysql.com (repo.mysql.com)... 184.50.240.231
#21 0.807 Connecting to repo.mysql.com (repo.mysql.com)|184.50.240.231|:443... connected.
#21 0.835 HTTP request sent, awaiting response... 200 OK
#21 0.843 Length: 18048 (18K) [application/x-debian-package]
#21 0.844 Saving to: 'mysql-apt-config_0.8.24-1_all.deb'
#21 0.844
#21 0.844      0K .......... .......                                    100%  218M=0s
#21 0.844
#21 0.844 2023-03-27 14:05:31 (218 MB/s) - 'mysql-apt-config_0.8.24-1_all.deb' saved [18048/18048]
#21 0.844
#21 DONE 0.9s
#22 [18/20] RUN dpkg -i mysql-apt-config_0.8.24-1_all.deb
#22 sha256:b05de8cdcf960039fcac126fb2313f94fac0decbfcf455f6a85d86fb506a9de1
#22 0.525 Selecting previously unselected package mysql-apt-config.
#22 0.532 (Reading database ... 22842 files and directories currently installed.)
#22 0.533 Preparing to unpack mysql-apt-config_0.8.24-1_all.deb ...
#22 0.539 Unpacking mysql-apt-config (0.8.24-1) ...
#22 0.567 Setting up mysql-apt-config (0.8.24-1) ...
#22 0.633 debconf: unable to initialize frontend: Dialog
#22 0.633 debconf: (TERM is not set, so the dialog frontend is not usable.)
#22 0.633 debconf: falling back to frontend: Readline
#22 0.639 debconf: unable to initialize frontend: Readline
#22 0.639 debconf: (This frontend requires a controlling tty.)
#22 0.639 debconf: falling back to frontend: Teletype
#22 0.654 Configuring mysql-apt-config
#22 0.654 ----------------------------
#22 0.654
#22 0.654 MySQL APT Repo features MySQL Server along with a variety of MySQL components.
#22 0.654 You may select the appropriate product to choose the version that you wish to
#22 0.654 receive.
#22 0.654
#22 0.654 Once you are satisfied with the configuration then select last option 'Ok' to
#22 0.654 save the configuration, then run 'apt-get update' to load package list.
#22 0.654 Advanced users can always change the configurations later, depending on their
#22 0.654 own needs.
#22 0.654
#22 0.654   1. MySQL Server & Cluster (Currently selected: mysql-8.0)
#22 0.654   2. MySQL Tools & Connectors (Currently selected: )
#22 0.654   3. MySQL Preview Packages (Currently selected: )
#22 0.654   4. Ok
#22 0.654 Which MySQL product do you wish to configure?
#22 0.654 Use of uninitialized value $_[1] in join or string at /usr/share/perl5/Debconf/DbDriver/Stack.pm line 111.
#22 0.696 Warning: apt-key should not be used in scripts (called from postinst maintainerscript of the package mysql-apt-config)
#22 0.696 Warning: apt-key is deprecated. Manage keyring files in trusted.gpg.d instead (see apt-key(8)).
#22 0.952 OK
#22 0.958 Use of uninitialized value $val in substitution (s///) at /usr/share/perl5/Debconf/Format/822.pm line 83, <GEN6> line 6.
#22 0.958 Use of uninitialized value $val in concatenation (.) or string at /usr/share/perl5/Debconf/Format/822.pm line 84, <GEN6> line 6.
#22 DONE 1.0s
#23 [19/20] RUN apt-get update
#23 sha256:bd568430616b2b4679343bb79ca842c8aec8d58faae3e879a6426765f2d0337d
#23 0.568 Hit:1 http://deb.debian.org/debian bullseye InRelease
#23 0.568 Hit:2 http://deb.debian.org/debian-security bullseye-security InRelease
#23 0.568 Get:3 http://repo.mysql.com/apt/debian buster InRelease [22.1 kB]
#23 0.571 Hit:4 http://deb.debian.org/debian bullseye-updates InRelease
#23 0.766 Get:5 http://repo.mysql.com/apt/debian buster/mysql-apt-config amd64 Packages [565 B]
#23 0.815 Fetched 22.7 kB in 0s (75.1 kB/s)
#23 0.815 Reading package lists...
#23 DONE 1.2s
#24 [20/20] RUN apt install mysql-client
#24 sha256:2e9cf25c1a502947e7a1ff06c705bf83bc3baae89638c46b33e6205ce2fef14f
#24 0.512
#24 0.512 WARNING: apt does not have a stable CLI interface. Use with caution in scripts.
#24 0.512
#24 0.517 Reading package lists...
#24 0.868 Building dependency tree...
#24 0.943 Reading state information...
#24 0.954 Package mysql-client is not available, but is referred to by another package.
#24 0.954 This may mean that the package is missing, has been obsoleted, or
#24 0.954 is only available from another source
#24 0.954
#24 0.990 E: Package 'mysql-client' has no installation candidate
#24 ERROR: process "/bin/sh -c apt install mysql-client" did not complete successfully: exit code: 100                                                                                                                                                                         ------                                                                                                                                                                                                                                                                          > [20/20] RUN apt install mysql-client:                                                                                                                                                                                                                                       ------                                                                                                                                                                                                                                                                         process "/bin/sh -c apt install mysql-client" did not complete successfully: exit code: 100 

debconf 似乎有一个问题,我们可以在这部分看到:

#22 0.633 debconf: unable to initialize frontend: Dialog
#22 0.633 debconf: (TERM is not set, so the dialog frontend is not usable.)
#22 0.633 debconf: falling back to frontend: Readline
#22 0.639 debconf: unable to initialize frontend: Readline
#22 0.639 debconf: (This frontend requires a controlling tty.)
#22 0.639 debconf: falling back to frontend: Teletype

如何解决该问题并使

mysql-apt-config
的静默安装按预期工作?

谢谢你。

docker mysql-connector silent-installer
2个回答
2
投票

@DavidMaze 发现了问题,但没有将其作为答案发布,所以这里是:

FROM node:latest

WORKDIR /usr/src/app

COPY package*.json ./

RUN npm install

COPY . .

RUN apt-get update && apt-get install -y lsb-release inetutils-tools
RUN wget https://dev.mysql.com/get/mysql-apt-config_0.8.24-1_all.deb
RUN DEBIAN_FRONTEND=noninteractive dpkg -i mysql-apt-config_0.8.24-1_all.deb
RUN apt-get update
RUN apt install -y mysql-client

EXPOSE 3000
CMD [ "node", "server.js" ]

DEBIAN_FRONTEND=noninteractive
指令中的
RUN dpkg
允许使用默认值安装
deb
文件。不需要
debconf-set-selections

此外,

-y
上的
RUN apt install -y mysql-client
参数是必要的。


0
投票

我更新了重要部分,在基于 debian bookworm (12) 的容器中安装 mysql-client 8.0

自从 mysql 8.4 发布以来,debconf 默认值应该使用正确的版本明确。

RUN wget http://repo.mysql.com/mysql-apt-config.deb
RUN bash -c "debconf-set-selections <<< 'mysql-apt-config  mysql-apt-config/select-server  select  mysql-8.0'"
RUN DEBIAN_FRONTEND=noninteractive dpkg -i mysql-apt-config.deb && apt-get update && apt-get install -y mysql-client

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