折腾了挺久,前提是需要在基础镜像里设置数据库的免密码登录。
编写run.sh,如下:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21
| #!/bin/bash set -e
echo `service mysql status`
chown -R mysql:mysql /var/lib/mysql echo '1.启动mysql....'
service mysql start sleep 3 echo `service mysql status`
mysql -uroot -proot echo '2.开始导入数据....'
mysql < /var/www/html/day1.sql echo '3.导入数据完毕....' sleep 3 echo `service mysql status`
echo `service mysql status`
|
Dockerfile的内容如下:
1 2 3 4 5 6 7
| FROM zhhhy/lampp
ADD ./day1/ /var/www/html RUN ls /var/www/html/ RUN chmod 777 /var/www/html/run.sh CMD ["sh","/var/www/html/run.sh"] EXPOSE 80
|
Author:
zhhhy
Permalink:
http://yoursite.com/2019/07/22/Dockerfile中写入数据/
License:
Copyright (c) 2019 CC-BY-NC-4.0 LICENSE
Solgan:
Do you believe in DESTINY?