Commit data in a mysql container

前端 未结 4 659
灰色年华
灰色年华 2021-01-11 12:41

I created a mysql container using the officially supported mysql image. I ran the image mounting a folder that contains a sql dump, then I created a new database in the cont

4条回答
  •  北荒
    北荒 (楼主)
    2021-01-11 13:31

    Based on @Robert answer, I ended up with this Dockerfile:

    FROM mysql:5.6.22
    
    RUN cp -r /var/lib/mysql /var/lib/mysql-no-volume
    
    RUN sed -i -e "s|/var/lib/mysql|/var/lib/mysql-no-volume|" /etc/mysql/my.cnf
    

    The CMD override didn't work for me, container stopped with a strange error:

    2019-02-21 15:18:50 1 [Note] Plugin 'FEDERATED' is disabled.
    mysqld: Table 'mysql.plugin' doesn't exist
    2019-02-21 15:18:50 1 [ERROR] Can't open the mysql.plugin table. Please run mysql_upgrade to create it.
    

    I guess that the original CMD command was doing more things that is now missing (in @Robert answer) so I did it in a different approach. I didn't try it with latest version but I think it should work.

提交回复
热议问题