After docker save can't connect mongo!! #556
Replies: 6 comments
-
WHY?Either docker commit can't save the changes in mongo container!! ### raw
docker run -itd --name mongo -p 27017:27017 mongo --auth
db.createUser({ user:'admin',pwd:'123456',roles:[ { role:'userAdminAnyDatabase', db: 'admin'},"readWriteAnyDatabase"]});
docker commit 1a40a0e27f42 mongo-commit:v1
### new
docker run it mongo-commit bash
# then no user in new container,I have set admin in old container... |
Beta Was this translation helpful? Give feedback.
-
Hi, @ch-boogeyman sudo docker run -d -p 27017:27017 --name mongo-test mongo mongod Execute |
Beta Was this translation helpful? Give feedback.
-
When a container is mirrored, the data it mounts on the host will not be attached to the mirror. ❯ docker inspect mongo-test | grep Mounts -A 21
"Mounts": [
{
"Type": "volume",
"Name": "3c9c2babfe7b189f401ea455c3ed11a0c2804737856de1c501d53bcbe31d99b7",
"Source": "/var/lib/docker/volumes/3c9c2babfe7b189f401ea455c3ed11a0c2804737856de1c501d53bcbe31d99b7/_data",
"Destination": "/data/configdb",
"Driver": "local",
"Mode": "",
"RW": true,
"Propagation": ""
},
{
"Type": "volume",
"Name": "0249ea8f46ab29e420d10f0ff1cf8ca344949e773d71cef7816460a62fa43d53",
"Source": "/var/lib/docker/volumes/0249ea8f46ab29e420d10f0ff1cf8ca344949e773d71cef7816460a62fa43d53/_data",
"Destination": "/data/db",
"Driver": "local",
"Mode": "",
"RW": true,
"Propagation": ""
}
], Notice that the data you created or modified at your old container is saved in your host such as The mount directory of your new container is impossible keeping data from your old container. |
Beta Was this translation helpful? Give feedback.
-
From a security point of view, you should not keep the database in the generated mirror. If you want to use the same database in the front and back containers, you can specify the same volume path for both containers. For example: sudo docker run -d -p 27017:27017 -v /data/mongo/db:/data/db -v /data/mongo/configdb:/data/configdb --name mongo-test mongo mongod It is worth noting that, the |
Beta Was this translation helpful? Give feedback.
-
Neither |
Beta Was this translation helpful? Give feedback.
-
Use docker |
Beta Was this translation helpful? Give feedback.
-
and then can't connect,see images
Beta Was this translation helpful? Give feedback.
All reactions