docker-compose:每次重新初始化MySQL数据库

时间:2016-09-29 17:38:25

标签: mysql ruby-on-rails docker docker-compose

我们有一个使用MySQL作为DB的Rails应用程序。 db的{​​{1}}部分看起来像

docker-compose.yml

并且在 db: image: mysql env_file: - ma.env volumes: - ./dump-db:/docker-entrypoint-initdb.d - ./my.cnf:/etc/mysql/my.cnf restart: always ports: - "3306:3306" environment: - MYSQL_HOST= 文件夹下实际上有我们db的sql-dump。

问题是,我们需要在每次./dump-db运行时加载精确的转储。 MySQL docker镜像以这种方式工作,它将它的数据存储在主机上,因此你的db-service不是无状态的。

我们需要的是docker-compose up服务放弃了db上次运行中完成的所有更改,并使用该确切转储重新启动。

2 个答案:

答案 0 :(得分:0)

解决

实际上,上面的想法给了我一些关于RTM的见解,这里就是

  • 获取自己的MySQL Dockerfile
  • 从中删除VOLUME行 它提到/var/lib/mysql应该安装在主机上。
  • docker-compose up --force-recreate db

答案 1 :(得分:-1)

如果您不希望每次执行$src1 = imagecreatefromstring( file_get_contents( $_FILES['image']['tmp_name'] ) ); $size1 = getimagesize( $_FILES['image']['tmp_name'] ); $dst1 = imagecreatetruecolor( 696, 400 ); imagecopyresampled( $dst1, $src1, 0, 0, 0, 0, 696, 399, $size1[0], $size1[1] ); imagedestroy( $src1 ); $width = 1200; $height = 687; $image = imagecreatetruecolor($width, $height); imagecopyresampled($image, imagecreatefrompng('images/main.png'),0,0,0,0,$width,$height,$width,$height); imagecopy($image, $dst1, 333, 103, 0, 0, 696, 399); $transparency = imagecolorallocatealpha($image, 0, 0, 0, 127); imagesavealpha($image, true); imagefill($image, 0, 0, $transparency); imagedestroy( $dst1 ); imagedestroy( $dst2 ); imagedestroy( $dst3 ); imagedestroy( $dst4 ); ob_start(); imagepng($image, NULL, 0); $size = ob_get_length(); header("Content-Length: " . $size); header("Cache-Control: private"); header("Content-Type: image/png"); header("Content-Disposition: attachment; filename=test.png"); 时都保留数据,则必须删除执行此命令所创建的卷。

要实现这一点,您可以执行以下命令,该命令将删除docker-compose up部分中声明的卷的db服务。

  

docker-compose down -v db