Commit data in a mysql container
The official mysql image stores data in a volume. Normally this is desired so that your data can persist beyond the life span of your container, but data volumes bypass the Union File System and are not committed to the image.
You can accomplish what you're trying to do by creating your own mysql base image with no volumes. You will then be able to add data and commit it to an image, but any data added to a running container after the commit will be lost when the container goes away.
Docker commit does not actually commit
Like David Maze pointed out, the original images I am building upon are already using volumes so my custom images are "inheriting" those volumes - even though I am not explicitly declaring any volumes in my own yaml file.
Couldn't find that documented anywhere I searched, so I hope this will help other beginners.
How to create a save MySQL container data to a docker image?
You will need to create a docker volume to maintain that information.
From the doc
Create a data directory on a suitable volume on your host system, e.g. /my/own/datadir.
Start your mysql container like this:
$ docker run --name some-mysql -v /my/own/datadir:/var/lib/mysql -e MYSQL_ROOT_PASSWORD=my-secret-pw -d mysql:tag
Docker-Compose persistent data MySQL
The data container is a superfluous workaround. Data-volumes would do the trick for you. Alter your docker-compose.yml
to:
version: '2'
services:
mysql:
container_name: flask_mysql
restart: always
image: mysql:latest
environment:
MYSQL_ROOT_PASSWORD: 'test_pass' # TODO: Change this
MYSQL_USER: 'test'
MYSQL_PASS: 'pass'
volumes:
- my-datavolume:/var/lib/mysql
volumes:
my-datavolume:
Docker will create the volume for you in the /var/lib/docker/volumes
folder. This volume persist as long as you are not typing docker-compose down -v
Related Topics
How to Query SQL For a Latest Record Date For Each User
Must Appear in the Group by Clause or Be Used in an Aggregate Function
Count(*) Vs. Count(1) Vs. Count(Pk): Which Is Better
Combining "Like" and "In" For SQL Server
How to Get Next/Previous Record in MySQL
Error in MySQL When Setting Default Value For Date or Datetime
How to Use an Insert Statement'S Output Clause to Get the Identity Value
Create a Date from Day Month and Year With T-Sql
In VS or in the SQL Where Clause
How to Select a Column Name With a Space in MySQL
How to Write a Full Outer Join Query in Access
Convert Utf-8 String Classic Asp to SQL Database