英文:
How do I upgrade mongo when using the docker images?
问题
我使用了官方的mongo docker镜像来部署mongo。希望升级mongo,但想知道如何操作?
经过一些研究和思考
- 似乎人们建议执行容器并在那里进行升级,但这看起来很不直观和奇怪
- mongodump/mongorestore 简单但也许这是最好的方法?
有更好的方法吗?
英文:
I used the official mongo docker image to deploy mongo. Am hoping to upgrade mongo but wonder how do I do it?
After some research/thought
- Seems like, ppl suggest exec into container and do the upgrade there but that seem very unintuitive and weird
- mongodump/mongorestore simple but maybe this works best?
Is there a better way?
答案1
得分: 1
我认为在Docker容器中升级MongoDB并不是最佳实践。最好的做法可能是通过以下方式拉取最新的MongoDB镜像来创建一个新的容器:
docker pull mongo:<目标版本>
在备份旧的MongoDB容器后,停止容器,然后可以通过以下方式删除它:
docker rm <你的容器>
然后,使用你拉取的新镜像启动一个新的容器。不要忘记附加你的数据。你可以使用以下命令:
docker run --name <你的容器> -v <你的数据>:<你的数据路径> -d mongo:<目标版本>
最后,如果你不小心丢失了数据,你也可以通过mongorestore
来恢复数据。这是该工具的文档链接:https://www.npmjs.com/package/connect-mongo
英文:
I don't think it's best practice to upgrade MongoDB in the docker container. It's probably better to have a new container by pulling the latest MongoDB image via:
docker pull mongo:<target_version>
After backing up your old MongoDB container, stop your container, then you can delete it via:
docker rm <your_cont>
Then, start a new container with your new image that you pulled. Don't forget to attach your data. You can use:
docker run --name <your_cont> -v <your_data>:<your_data_path> -d mongo:<target_version>
Finally, you can also restore your data via mongorestore
if you ever lose it. Here's the documentation for that tool: https://www.npmjs.com/package/connect-mongo
通过集体智慧和协作来改善编程学习和解决问题的方式。致力于成为全球开发者共同参与的知识库,让每个人都能够通过互相帮助和分享经验来进步。
评论