如何在Docker容器中升级Strapi?

时间:2019-04-27 11:15:56

标签: docker strapi

我使用Docker-compose启动了Strapi。阅读Migration Guide之后,我仍然不知道是否要升级到下一个版本,应该选择哪种方法:

  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> -gnpm install strapi@<next version> --save
  3. 都没有?

2 个答案:

答案 0 :(得分:0)

  1. 在本地开发人员树中,更新package.json文件中的软件包版本。在本地运行npm installyarn install。启动您的应用程序。验证它是否有效。运行测试。修复升级中的所有兼容性问题。完全不用Docker就可以完成所有这些工作。

  2. 重新运行docker build .以使用新的程序包依赖关系重建Docker映像。

  3. 停止旧容器,将其删除,然后使用新映像运行新容器。

作为一般规则,切勿在正在运行的容器中安装任何物品。删除容器是极为常规的操作,执行此操作后,容器中的所有内容都会丢失。

有一个常见的“模式”,即在Docker中运行Node,将应用程序绑定安装到其中,然后在node_modules目录上安装匿名卷。对于常规开发,我发现仅将Node安装在主机上就简单得多(实际上是单个apt-get installbrew install命令)。如果您使用的是面向Docker的设置,那么node_modules的匿名卷将不会注意到您已经更改了node_modules目录,因此您必须重新运行docker build并删除并重新创建您的容器。

答案 1 :(得分:0)

TLDR:3,而 2 的方向是正确的。

官方文档对我来说也是第一次不清楚。 以下是 docker-compose 上下文中从 3.0.5 到 3.1.5 的分步指南。

它尽可能地遵循官方文档,但包括一些额外的(在我的情况下是强制性的)步骤。

<块引用>

升级 Strapi

  • 以下内容涉及通过 strapi/strapi 使用的 strapi/base(而非 docker-compose)docker 映像
  • 重要提示! 升级 Docker 镜像版本不会升级 Strapi 版本。
    • Strapi NodeJS 应用程序仅在第一次启动时自行构建,如果检测到空文件夹并且通常存储在安装的卷中。见docker-entrypoint.sh
  • 要升级,请首先按照指南(generalversion-specific)重建实际的 Strapi NodeJS 应用程序。其次,更新 docker 标签以匹配版本以避免混淆。

从 3.0.5 升级到 3.1.5 的示例:

# https://strapi.io/documentation/developer-docs/latest/guides/update-version.html

# Make sure your server is not running until the end of the migration
## That is unclear instruction. Stopped Nginx to prevent access to application, without stopping Strapi itself. 
docker-compose exec strapi bash # enter running container
## Alternative way would be `docker-compose stop strapi` and manually reconstruct container options using `docker`, overriding entrypoint with `--entrypoint /bin/bash`

# Few checks
yarn strapi version # current version installed
yarn info strapi #npm info strapi@3.1.x version # available versions
yarn --version #npm --version
yarn list #npm list
cat package.json

# Upgrade your dependencies
sed -i 's|"3.0.5"|"3.1.5"|g' package.json && cat package.json
yarn install #npm install
yarn strapi version

  # Breaking changes? See version-specific migration guide!

  ## https://strapi.io/documentation/developer-docs/latest/migration-guide/migration-guide-3.0.x-to-3.1.x.html
    ## Define the admin JWT Token
    ## Update username constraint for administrators
    docker-compose exec db bash
    psql strapi strapi
      -- show tables and describe one
      \dt
      \d strapi_administrator
    ## Migrate your custom admin panel plugins

# Rebuild your administration panel
rm -rf node_modules # workaround for "Error: Module not found: Error: Can't resolve"
yarn build --clean #npm run build -- --clean

  # Extensions?

# Start your application
yarn develop #npm run develop
# Confirm & test, visit URL

  # Errors?

  ## Error: ENOSPC: System limit for number of file watchers reached, ...
  # Can be solved by modifying kernel parameter at docker HOST system
  sudo vi /etc/sysctl.conf # fs.inotify.max_user_watches=524288
  sudo sysctl -p

# Modify docker-compose to reflect version changed and avoid confusion !
docker ps
vi docker-compose.yml # e.g. 3.0.5 > 3.1.5
docker-compose up --force-recreate --no-deps -d strapi
# ... and remove old docker image, when no longer required.

附言我们可能会通过 https://github.com/strapi/documentation 共同改进文档。提出拉取请求 https://github.com/strapi/strapi-docker/pull/276