0

I have a container that ran and stopped it's processes after build. I'd like to use that state to build on top of it (like using its data from first run). I did it with a MySQL image (hoping the data will be stored) as follows (there are other containers in the compose as well, that is aimed to connect to this MySQL instance):

mysql:
  image: mysql-custom
  command: mysqld --user=root
  environment:
      MYSQL_ROOT_PASSWORD: "toor"
      MYSQL_ALLOW_EMPTY_PASSWORD: "yes"

mysql-custom is the commit image that has the data during the first run. Is this possible, to have the data in and build that MySQL instance again with the same data, or am I doing something unacceptably wrong here?

coras09
  • 333
  • 3
  • 11
  • It is. Didn't find this whilst searching. Thank you very much, I'll use volumes to achieve the system setup then. – coras09 Sep 06 '18 at 13:25

2 Answers2

1

Yes this is possible, to have the data in and build that instance again with the same data,(mounted volumes are not considered) in case only if you directly kept your data on container

  • It should, but when another instance uses the update one, the tables are not there. I was wondering if it's because I'm directly giving the image tag, hence building differently, rather than having a Dockerfile for it. – coras09 Sep 05 '18 at 16:00
1

Yes, you can have the state in your custom image built over another image. https://blog.codeship.com/using-docker-commit-to-create-and-change-an-image/

But unable to understand your use case, can you please explain that maybe I can suggest accordingly?

Hemant Singh
  • 1,487
  • 10
  • 15
  • Basically, this image will have all the tables and initial data, so another instance can use, change data and delete data as it wishes. Like a template DB for the system. – coras09 Sep 05 '18 at 15:25
  • 2
    It completely makes sense, I will suggest having a Dockerfile to build this custom wrapper image. You can refer to https://stackoverflow.com/questions/29145370/how-can-i-initialize-a-mysql-database-with-schema-in-a-docker-container – Hemant Singh Sep 05 '18 at 15:28
  • 1
    The thing is, we'd like to have this process automated, and ran by the system that initialises this, which can change. By this method we need an .sql dump already, which might be outdated after some time for the recent system. If the method I suggest is not possible though I think your solution is the best suitable. – coras09 Sep 05 '18 at 15:59