Persistent data in MySQL with Docker If I startup MySQL server during docker build (derived from official MySQL Dokcer Image) in two different statements, would be database files be pertained?

I would say yes, but it seems to be wrong. Why?

Logfile:

180228 08:54:50 mysqld_safe Logging to '/var/lib/mysql/c2712433a4da.err'.
180228 08:54:50 mysqld_safe Starting mysqld daemon with databases from /var/lib/mysql
mysql: [Warning] Using a password on the command line interface can be insecure.
mysql: [Warning] Using a password on the command line interface can be insecure.
Tables_in_FOOBAR
address
category
Removing intermediate container b3ff83bbf273
 ---&gt; 0b366a0d31a9
Step 9/9 : RUN chmod 777 /var/lib/ -R &amp;&amp; ./ingest_data.sh 
 ---&gt; Running in 149361f7d465
180228 08:55:00 mysqld_safe Logging to '/var/lib/mysql/c2712433a4da.err'.
180228 08:55:00 mysqld_safe Starting mysqld daemon with databases from /var/lib/mysql
mysql: [Warning] Using a password on the command line interface can be insecure.
Database
information_schema
mysql: [Warning] Using a password on the command line interface can be insecure.
ERROR 1049 (42000): Unknown database 'FOOBAR'


As you can see, in the first RUN statement I can list tables I have created in a new database, but in the second RUN statement the database is gone.

Note. Normally, you would not transport your application data in production containers (immutability principle) but for demo and test purposes this can be nevertheless useful.
That's a known issue .. since image layers are built using containers, data saved to folders does not make it to the next layer or your final container

Removing intermediate container b3ff83bbf273


If you want data to persist between updated containers you have to manually map data to the host outside the container-specific mount points.

For example, when creating a container use the -v option to map a volume:

docker run -d -v /var/container_data/mysql:/var/lib/mysql mysql_image


For a detailed documentation 
https://docs.docker.com/engine/reference/run/#volume-shared-filesystems