如何在dockerfile中设置mysql用户名 [英] How to set mysql username in dockerfile

查看:887
本文介绍了如何在dockerfile中设置mysql用户名的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

在ubuntu中使用 apt-get install mysql-server 安装mysql时,在安装过程中会询问mysql用户名和密码。



但是当使用dockerfile构建mysql镜像时,如何提供用户名和密码?



我尝试使用dockerfile,如下所示: / p>

  FROM ubuntu:14.04 
apt-get update
apt-get install -y mysql-server

但是,当构建映像时,我发现我们可以登录mysql,没有用户名和密码。 >

当我使用dockerfile构建我的图像时,如何设置用户名和密码?

解决方案

如果您查看官方的Docker MySQL映像,请 Dockerfile ,您将发现他们如何使用 debconf-set-choices



相关说明是:

  RUN {\ 
echo mysql-community-server mysql-community-server / data-dir select''; \
echo mysql-community-server mysql-community-server / root-pass password''; \
echo mysql-community-server mysql-community-server / re-root-pass password''; \
echo mysql-community-server mysql-community-server / remove-test-db select false; \
} | debconf-set-choices \
&& apt-get update&& apt-get install -y mysql-server

debconf-set-choices / code>是一个工具,可以让您为稍后安装过程中将提出的问题准备答案。


When installing mysql in ubuntu with apt-get install mysql-server, the mysql username and password are asked during the installation.

But when using a dockerfile to build a mysql image, how can the username and password be provided?

I tried using the dockerfile as follows:

FROM ubuntu:14.04
apt-get update
apt-get install -y mysql-server

But when building the image, I found out we can login in the mysql without username and password.

How can I set the username and password when I use dockerfile to build my images?

解决方案

If you take a look at the official Docker MySQL image Dockerfile, you will discover how they did it using debconf-set-selections.

The relevant instructions are:

RUN { \
        echo mysql-community-server mysql-community-server/data-dir select ''; \
        echo mysql-community-server mysql-community-server/root-pass password ''; \
        echo mysql-community-server mysql-community-server/re-root-pass password ''; \
        echo mysql-community-server mysql-community-server/remove-test-db select false; \
    } | debconf-set-selections \
    && apt-get update && apt-get install -y mysql-server

debconf-set-selections is a tool that allows you to prepare the answers for the questions that will be asked during the later installation.

这篇关于如何在dockerfile中设置mysql用户名的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆