Docker 中的 MySQL 冻结在 root 密码配置中

2024-03-14

我有下一个 dockerfile:

FROM ubuntu:16.04
RUN apt-get update && apt-get upgrade -y && apt-get install -y apache2 mysql-server mysql-client

之后,Docker 构建询问我 root 密码:

While not mandatory, it is highly recommended that you set a password for the
MySQL administrative "root" user.

If this field is left blank, the password will not be changed.

New password for the MySQL "root" user:

我输入了密码,但是它只是保持该状态。

我可以这样安装mysql吗?,我不想自动安装


接受的答案在某种抽象意义上可能是正确的,但与当前的问题完全无关。您需要一种静态指定密码的方法。除非你正在使用官方形象 https://hub.docker.com/_/mysql/,无论您是否遵循“一个进程,一个容器”的教条,您都需要它。

答案here https://stackoverflow.com/a/32146887/577088告诉了如何做,但它遗漏了一个关键设置:你仍然必须告诉debconf使用Noninteractive前端,如上所述here https://github.com/phusion/baseimage-docker/issues/58#issuecomment-47995343.

这是一个工作示例Dockerfile基于上述。

FROM ubuntu:latest
MAINTAINER Jonathan Strange <[email protected] /cdn-cgi/l/email-protection>
RUN apt-get update \
    && apt-get install -y apt-utils \                                           
    && { \
        echo debconf debconf/frontend select Noninteractive; \
        echo mysql-community-server mysql-community-server/data-dir \
            select ''; \
        echo mysql-community-server mysql-community-server/root-pass \
            password 'JohnUskglass'; \
        echo mysql-community-server mysql-community-server/re-root-pass \
            password 'JohnUskglass'; \
        echo mysql-community-server mysql-community-server/remove-test-db \
            select true; \
    } | debconf-set-selections \
    && apt-get install -y mysql-server apache2 python python-django \
        python-celery rabbitmq-server git

这与我们所看到的并没有太大不同官方的Dockerfile https://github.com/docker-library/mysql/blob/ad625c64a06e16683e997e5a0147508d115f4989/8.0/Dockerfile确实如此——尽管他们处理实际密码配置的方式有些不同。

有些人已经取得了成功设置 DEBIAN_FRONTEND https://github.com/phusion/baseimage-docker/issues/58#issuecomment-57900765环境变量为noninteractive,像这样:

ENV DEBIAN_FRONTEND noninteractive

然而,这似乎并不适用于所有情况。使用debconf事实证明直接对我来说更可靠。

本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)

Docker 中的 MySQL 冻结在 root 密码配置中 的相关文章

随机推荐