What should be prepared in advance for port and data backup when deploying the enterprise website with Docker?
To run the enterprise website with Docker, many people only pay attention to whether the 'image can be started', but are stuck at two things that were not prepared in advance when providing services to the outside world: port and data backup. If the port is not planned well, the service will start but cannot be accessed from outside; if the backup is not kept well, once the container is rebuilt, the data and the uploaded static files will be lost together. These two things are the most convenient to do before going online, and the cost of补 after going online is high. The deployment method of AnQiCMS includes Docker images, which are matched with the built-in backup and recovery capabilities, just corresponding to these two things.
How to determine the image and port mapping
The system provides a Docker image named anqicms/anqicms, which can bring up the site with a single command. This is also one of the points that makes it easier to deploy compared to the traditional PHP environment. However, the ports inside the container and the external ports of the host are two different things: the service inside the container listens to the default port 8001, and the host needs to decide which port to use externally, whether to use reverse proxy to convert it to 80 or 443, and these need to be considered before starting the container.
The common practice is to keep the default port 8001 inside the container, and then expose it to the outside through port mapping on the host machine. When setting the port, there are three points that need to be confirmed in advance: first, whether the target port on the host machine is occupied, second, whether the firewall and security group allow it, and third, when multiple sites coexist, the ports should not collide with each other. Writing the mapping relationship into the deployment instructions is much more stable than temporarily trying the ports.
How does the default port go out to the outside?
Default to listen on port 8001, this matter is easy to ignore, leading to 'Can be opened locally, but not on the Internet'. The reason is usually that only the container was started, no port mapping was done, or the mapping was done but the cloud server security group did not allow it. The correct link is: users visit the domain name, the reverse proxy receives on the host machine, and then forwards to the external mapping port of the container, finally landing on port 8001 within the container. If any link in the chain is not properly configured, external access is not possible. Therefore, before going online, the entire link should be verified in a complete loop, rather than just testing internally within the container and thinking that the deployment is complete.
How to keep data backup before going online
A feature of Docker is that the environment can be replaced, but the prerequisite for replacement is that the data can be recovered. The system's backup and recovery capabilities cover data and static files, that is, the content of the database and the resources such as uploaded images are all within the scope of backup, and can be restored when recovered. Before going online, it is necessary to confirm three things: the backup product falls on the container's persistent volume or host directory, rather than just in the writable layer of the container; the backup has a fixed rhythm rather than just a manual click once; the recovery process has been practiced once, knowing how to pull the site back from the backup.
It is particularly important to include static files in the backup. If the pictures and attachments on the official website only exist in the container, they will be lost when the container is rebuilt, and these are exactly the contents that are the most difficult to regenerate. Planning ports and planning backups are essentially two sides of the same thing: the former ensures that the service can provide services externally, and the latter ensures that the service can restart at any time.
Common questions
Do you have to use the default 8001 port?It is not necessary to expose 8001 externally, commonly used externally are 80 or 443; 8001 is mostly used as the port of the container service, which can be forwarded by the reverse proxy.
Will the data be lost if the container is deleted?As long as the data and static files are placed in a persistent volume and have a backup, they will not be lost; what is often lost is the part that has not been persisted or backed up.
What is the most important thing to verify before going live?Verify whether the access path 'domain to container 8001' is working, and then verify again whether the site can be brought up from the backup.