DockerFile
ENV MYSQL_ROOT_PASSWORD 123456
ENV MYSQL_USER user
ENV MYSQL_PASSWORD password
ENV MYSQL_ROOT_HOST percentage
ENV WORK_PATH=/usr/workdir
VOLUME C:\code\mysql\conf:/etc/mysql
VOLUME C:\code\mysql\logs:/logs
RUN mkdir -p $WORK_PATH
COPY schema.sql $WORK_PATH
COPY install.sh /docker-entrypoint-initdb.d
RUN chmod a plus x/Docker-entrypoint-initdb.d/install.sh
Warning
[Warning] root@localhost is created with an empty password ! Please consider switching off the --initialize-insecure option.
Build image statement
docker build -t mysql:tag /path
Run statement
docker run --name mysql_name -idt -p 3306:3306 mysql:tag
docker run -e MYSQL_ROOT_PASSWORD=123456
This will only take effect