0

In my Dockerfile I install MySql-Server

FROM ubuntu:latest

# INSTALL MYSQL
RUN apt -y update
RUN apt -y install mysql-server
RUN service mysql start

but what root password is it now? Is there a easier way to maybe install MySql-Server and intially load a mysql-dump-file?

1 Answer 1

1

The easiest way is to use the MySQL offical docker image, which has proper entrypoint and manages complex task like setting an initial password and DB dumb on boot or during build time if you extend from base image.

You just need to use below docker-compose and map your DB file to /docker-entrypoint-initdb.d.

# Use root/example as user/password credentials
version: '3.1'

services:

  db:
    image: mysql
    command: --default-authentication-plugin=mysql_native_password
    restart: always
    environment:
      MYSQL_ROOT_PASSWORD: example

  adminer:
    image: adminer
    restart: always
    ports:
      - 8080:8080

Currently, this is only supported for MYSQL_ROOT_PASSWORD, MYSQL_ROOT_HOST, MYSQL_DATABASE, MYSQL_USER, and MYSQL_PASSWORD.

Initializing a fresh instance

When a container is started for the first time, a new database with the specified name will be created and initialized with the provided configuration variables. Furthermore, it will execute files with extensions .sh, .sql and .sql.gz that are found in /docker-entrypoint-initdb.d. Files will be executed in alphabetical order. You can easily populate your mysql services by mounting a SQL dump into that directory and provide custom images with contributed data. SQL files will be imported by default to the database specified by the MYSQL_DATABASE variable.

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.