When deploying a content system in container mode, what should be confirmed first: port mapping and data backup?
What needs to be confirmed first for container deployment of the content management system, port mapping and data backup? The sequence is three steps: first, confirm which port the exposed image is mapped to on the host machine, then confirm whether the upload directory and database are outside the container, and finally confirm that the backup can truly recover. Taking the AnQiCMS Docker image as an exampleanqicms/anqicmsFor example, the application listens to the default port 8001, this step needs to be set in advance before starting the container, rather than changing it after it starts.
Three things need to be determined before deployment.
The first thing is the port form. The default listening port 8001 is the application port inside the container, the public network access is usually handled by a reverse proxy, which transfers 80 and 443 into it. It is rare to expose 8001 directly to the public network, most of the time, the proxy is placed in front, and the proxy terminates the certificate and jump.
The second thing is the data landing point. The container is disposable, and the content in the image will be overwritten when rebuilt, so the backup copies of uploaded images, attachments, and template modifications should point to the mounted directory. The third thing is the backup ownership: the backup is produced by the on-site function, but the product should be placed outside the container, otherwise, once rebuilt, both the program and the backup will be lost.
How to write port mapping and reverse proxy
After confirming the mapping relationship, you still need to check which header information the proxy has forwarded. The application generates absolute addresses and depends on these headers to judge the source protocol, and if the forwarding is missing, it will cause the address configured in the background to be inconsistent with the actual access address from the front-end. The static rules at this level also need to align: the rewriting rules within the container and the forwarding path at the proxy layer should follow the same set of conventions, otherwise, the front-end page can be accessed, but the address in the sitemap cannot be accessed.
| Inspection items | The position to be confirmed outside the container | The behavior after an error |
|---|---|---|
| Application port | The mapping relationship between the container internal port 8001 and the host port | The proxy is reachable but the background link points to the wrong port |
| Forwarding header | Proxy layer protocol and source hostname setting | The generated resource address becomes http or points to the intranet |
| Static rules | The rule file and proxy forwarding path are consistent | List page is accessible, detail page reports 404 |
| Upload directory | Mounted to the host machine or object storage persistent volume | The newly uploaded image is lost after the container is rebuilt |
| Backup product | The storage location of data backup and static file backup | Backup is deleted along with the program |
Data must be stored outside the container
There are two common practices for databases: using the database service inside the container, or connecting to an external database. The former must mount the data directory, otherwise it will be lost after restart; the latter must strip the connection configuration from the image to avoid rebuilding the image when changing environments. The same is true for the upload directory and configuration files, any content that needs to be effective after modification or needs to be redone if lost should be in the persistent volume.
Multiple site scenarios require an extra layer of attention. AnQiCMS supports multi-site management, with a single program managing multiple independent sites. At this point, the container boundary and the site boundary are not the same thing: a single container carrying multiple sites means that a single rebuild will affect all sites, so how many sites to host on each host machine should be allocated according to risk at the deployment stage, rather than merging when capacity is tight.
The backup must be able to really recover.
The backup capability within the site covers two types of products: data and static files. The check method involves a full recovery process rather than just checking if the files exist: start the same version image on an isolated machine, mount a clean directory, put the backup in and restore it, then check if the homepage, list page, and an article with images can normally access the resources. After the recovery is complete, it is convenient to check the 301 redirect configuration, as the redirection of the old address after the address change is part of the front-end experience.
Websites deployed on operation and maintenance panels such as Baota Panel or aaPanel, and also confirm whether the scheduled tasks of the panel conflict with container rebuilds: If the backup path of the panel points to a temporary directory inside the container, the output will be an empty directory snapshot.
Common questions
Question: Do you need to back up the template files modified in the container separately?Answer: Template modifications belong to content outside the container. You can write it in the mounted directory and back it up with the data; if you modify it directly in the image, it will be lost during rebuild.
Question: Can the default port 8001 be used directly externally?Answer: It can be done but is not recommended. The external port is handed over to the reverse proxy, the application port is only accessible within the internal network, and certificates and redirects are all handled at the proxy layer.
Question: How should we handle the recovery when multiple sites share a single container?Answer: Check separately whether the data and static files of each site are complete. After recovery, visit each site's homepage and representative page one by one to confirm that the addresses and redirects do not overlap.
Question: Why do we need to confirm the pseudo-static in the container an extra time?Answer: The rule files within the container and the forwarding of the proxy layer are two configurations. If they are not aligned at either place, it will result in the page being accessible, but failing when retrieving addresses according to the site map.