Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

MySQL in Docker frozen at root password config

I have the next dockerfile:

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

After, Docker build asking me the password 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:

I enter the password, but, simply it stays in that state.

Can I install mysql this way?, I do not want to install it automatically

like image 950
alvarezsh Avatar asked Jul 13 '16 15:07

alvarezsh


People also ask

How set MySQL root password Docker?

Logging into the MySQL Server You will be prompted for the root user's password. Use the password revealed by the docker logs mysql01 command. Once within the MySQL server, you can then change the password with the command: ALTER USER 'root'@'localhost' IDENTIFIED BY 'newpassword';

What is the password for root MySQL?

The default user for MySQL is root and by default it has no password. If you set a password for MySQL and you can't recall it, you can always reset it and choose another one.

How set MySQL root password after installation?

Use the following procedure to set a root password. To change the root password, type the following at the MySQL/MariaDB command prompt: ALTER USER 'root'@'localhost' IDENTIFIED BY 'MyN3wP4ssw0rd'; flush privileges; exit; Store the new password in a secure location.

How do I log into MySQL Docker?

Step 1: Pull the Docker Image for MySQL. Step 2: Deploy and Start the MySQL Container. Step 3: Connect with the Docker MySQL Container.


1 Answers

The accepted answer may be true in some abstract sense, but it's completely irrelevant to the matter at hand. You need a way to specify the password statically. And unless you are using the official image, you'll need that whether or not you follow the "one process, one container" dogma.

The answer here tells how, but it leaves out a key setting: you still have to tell debconf to use the Noninteractive front-end, as described here.

Here's an example of a working Dockerfile based on the above.

FROM ubuntu:latest
MAINTAINER Jonathan Strange <[email protected]>
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

This is not too terribly different from what the official Dockerfile does -- though they handle the actual password config somewhat differently.

Some people have had success by setting the DEBIAN_FRONTEND environment variable to noninteractive, like so:

ENV DEBIAN_FRONTEND noninteractive

However, that doesn't seem to work in all cases. Using debconf directly has proven more reliable for me.

like image 77
senderle Avatar answered Oct 02 '22 03:10

senderle