This document introduces how to share WordPress attachments across different containers by creating OSSFS data volumes in Alibaba Cloud Container Service.
Docker containers simplify WordPress deployment. With Alibaba Cloud Container Service, you can use an orchestration template to deploy WordPress with one click.
|For more information, see Create WordPress with an orchestration template.|
In this example, the following orchestration template is used to create an application named wordpress.
web: image: registry.aliyuncs.com/acs-sample/wordpress:4.3 ports: - '80' environment: WORDPRESS_AUTH_KEY: changeme WORDPRESS_SECURE_AUTH_KEY: changeme WORDPRESS_LOGGED_IN_KEY: changeme WORDPRESS_NONCE_KEY: changeme WORDPRESS_AUTH_SALT: changeme WORDPRESS_SECURE_AUTH_SALT: changeme WORDPRESS_LOGGED_IN_SALT: changeme WORDPRESS_NONCE_SALT: changeme WORDPRESS_NONCE_AA: changeme restart: always links: - 'db:mysql' labels: aliyun.logs: /var/log aliyun.probe.url: http://container/license.txt aliyun.probe.initial_delay_seconds: '10' aliyun.routing.port_80: http://wordpress aliyun.scale: '3' db: image: registry.aliyuncs.com/acs-sample/mysql:5.7 environment: MYSQL_ROOT_PASSWORD: password restart: always labels: aliyun.logs: /var/log/mysql
This application contains a MySQL container and three WordPress containers (
aliyun.scale: '3' is the extension label of Alibaba Cloud Container Service, and specifies the number of containers. For more information about the labels supported by Alibaba Cloud Container Service, see Label description). The WordPress containers access MySQL by using a link. The
aliyun.routing.port_80: http://wordpress label defines the load balancing among the three WordPress containers (for more information, see Simple routing - Supports HTTP and HTTPS).
In this example, the application deployment is simple and the deployed application is of complete features. However, the attachments uploaded by WordPress are stored in the local disk, which means they cannot be shared across different containers or opened when requests are routed to other containers.
This document introduces how to use OSSFS data volumes of Alibaba Cloud Container Service to share WordPress attachments across different containers, without any code modifications.
OSSFS data volume, a third-party data volume provided by Alibaba Cloud Container Service, packages various cloud storages (such as Object Storage Service (OSS)) as data volumes and then directly mounts them to the containers. This means the data volumes can be shared across different containers and automatically re-mounted to the containers when the containers are restarted or migrated.
- Create OSSFS data volumes.
In this example, the created OSSFS data volumes are named wp_upload. Container Service uses the same name to create data volumes on each node of a cluster. As shown in the following figure.
- Log on to the Container Service console. Under Swarm, click Data Volumes in the left-side navigation pane.
- Select the cluster in which you want to create data volumes from the Cluster drop-down list. Click Create in the upper-right corner to create the OSSFS data volumes.
For how to create OSSFS data volumes, see Create an OSSFS data volume.
- Use the OSSFS data volumes.
The WordPress attachments are stored in the /var/www/html/wp-content/uploads directory by default. In this example, map OSSFS data volumes to this directory and then an OSS bucket can be shared across different WordPress containers.
- Log on to the Container Service console. Under Swarm, Click Applications in the left-side navigation pane.
- Select the cluster used in this example from the Cluster drop-down list. Click Update at the right of the application wordpress created in this example.
- In the Template field, add the mapping from OSSFS data volumes to the WordPress directory.
Note You must modify the Version. Otherwise, the application cannot be redeployed.
- Click OK to redeploy the application.
- Open WordPress and upload attachments. Then, you can see the uploaded attachments in the OSS bucket.