Why isn't docker commit saving data in my mongo database container?


December 2018


846 time


I have a docker-compose file that links a seed script with a mongo image from docker's public registry. I can populate the database with:

docker-compose up
docker-compose run seed_script

I can connect to this mongo container with the mongo cli from my host system and verify that the seed script is working and there's data in the database.

When I'm done seeding, I can see the mongo container ID with docker ps. I stop the container by pressing Ctrlc in the docker-compose terminal and commit the changes to the mongo container:

docker commit <mongo container ID> mongo-seeded-data

However, when I run that container individually, it's empty:

docker run -p 27017:27017 mongo-seeded-data

> show dbs
local  0.000GB

If I bring up the docker-compose containers again and use my host mongo client, I can see the data:

docker-compose up

> show dbs
seeded_db  0.018GB
local      0.000GB

I committed the container with the data in it. Why is it not there when I bring up the container? What is docker-compose doing differently than docker run?


0 answers