首页 > 解决方案 > 如何在 Docker 容器中升级 Strapi?

问题描述

我用 Docker-compose启动了Strapi 。看了迁移指南,还是不知道要不要升级到下一个版本,应该选择什么方法:

  1. 在 Strapi 项目目录下,执行npm install strapi@<next version> -gnpm install strapi@<next version> --save
  2. docker exec -it <strapi container> sh,导航到 Strapi 项目目录,然后npm install strapi@<next version> -g执行npm install strapi@<next version> --save
  3. 两者都不?

标签: dockerstrapi

解决方案


  1. In your local developer tree, update the package version in your package.json file. Run npm install or yarn install locally. Start your application. Verify that it works. Run your tests. Fix any compatibility issues from the upgrade. Do all of this without Docker involved at all.

  2. Re-run docker build . to rebuild your Docker image with the new package dependencies.

  3. Stop the old container, delete it, and run a new container with the new image.

As a general rule you should never install anything in a running container. It's extremely routine to delete containers, and when you do, anything in the container will be lost.

There's a common "pattern" of running Node in Docker, bind-mounting your application into it, and then mounting an anonymous volume over your node_modules directory. For routine development I've found it vastly simpler to just install Node on my host (it is literally a single apt-get install or brew install command). If you're using this Docker-oriented setup, the anonymous volume for node_modules won't notice that you've changed your node_modules directory, and you have to re-run docker build and delete and recreate your containers.


推荐阅读