# 使用docker-compose整合MySQL

**若要將nextcloud的資料庫改用mysql或mariadb，那就需要啟動一個資料庫的容器，並將兩者整合使用，單純使用docker指令設定當然可以，但是相當麻煩，有沒有比較能一目了然且簡單的作法，那就使用docker-compose**<br>

**移除先前SQLite的設定，所以移除/mnt/raid/nextcloud**

**rm -rf /mnt/raid/nextcloud**<br>

**建立docker-compose.yaml設定檔**

**version: '2'**

**services:**

&#x20; **db:**

&#x20;   **image: mariadb:10**

&#x20;   **container\_name: nextcloudDB**

&#x20;   **restart: always**

&#x20;   **volumes:**

&#x20;     **- /mnt/raid/nextcloud/mysql:/var/lib/mysql**

&#x20;     **- /etc/localtime:/etc/localtime:ro**

&#x20;   **environment:**

&#x20;     **- MYSQL\_ROOT\_PASSWORD=1234**

&#x20;     **- MYSQL\_PASSWORD=1234**

&#x20;     **- MYSQL\_DATABASE=nextcloud**

&#x20;     **- MYSQL\_USER=nextcloud**

&#x20;   **networks:**

&#x20;     **nextcloud:**

&#x20;       **ipv4\_address: 10.1.1.2**<br>

&#x20; **app:**

&#x20;   **image: nextcloud**

&#x20;   **container\_name: nextcloud**

&#x20;   **ports:**

&#x20;     **- 8080:80**

&#x20;   **links:**

&#x20;     **- db**

&#x20;   **volumes:**

&#x20;     **- /mnt/raid/nextcloud:/var/www/html**

&#x20;     **- /etc/localtime:/etc/localtime:ro**

&#x20;   **restart: always**

&#x20;   **networks:**

&#x20;     **nextcloud:**

&#x20;       **ipv4\_address: 10.1.1.3**

**networks:**

&#x20; **nextcloud:**

&#x20;   **driver: bridge**

&#x20;   **ipam:**

&#x20;    **config:**

&#x20;      **- subnet: 10.1.1.0/24**

&#x20;        **gateway: 10.1.1.1**

{% file src="/files/-LjtjhQU7cjjdNI4Ndcz" %}
nextcloud docker-compose.yaml
{% endfile %}

**以下面一行指令完成**

**docker-compose up -d**<br>

**進入 portainer管理頁面，你可以看到 nextcloud 與 mysql的IP網段被設定到我們自訂的區段，並且不使用dhcp，使用固定ip，如此，方不會於重新製作容器時，讓nextcloud找不到資料庫**

![](https://lh3.googleusercontent.com/sZKyjjySde-hVYmHsOkUrVcTXVXRaJfHmau3Z0xvgJJ-n6Eyu1hZy_POyBFYwnBO_EWrp0nRpHpD9IZl5ishOQIi2EmJhbX3xv6N_UCRx7nAP_vTdsEhWDN9GCYeENMhfWgJ44Yz)

**關閉並移除容器的所有設定**

**docker-compose down**

**進入 ip:8080，會要你重設系統，此時改用mysql，注意ip使用自定的固定ip**

![](https://lh3.googleusercontent.com/WNFUk6itTmvKrUeT0aSkS2hXe7pTVeyw0c2NYAsaTt6dt_wuYAby3lSo2fRtqEv9ynhWJ9mU_VWk4Bj9f3C6a2URyPJ-_ZZUAiHMr36MxhrnDUrd6qBLvvi-EQZjiAWrcQvvre2L)

**桌面與手機的同步軟體**

**你可以到nextcloud官網或個人設定中的『同步客戶端』來安裝client端的同步軟體，其用法與Dropbox等類型軟體市相同的，差別只是nextcloud完全是屬於個人的私有雲**

![](https://lh4.googleusercontent.com/esGuNK0slF2d_69qQ5txan4f-dPaU_UbW4xY2KHsGU4T7vaL5rvPvuNMr5n-LVhMtonf1km1nl9op0ffy8WVr1t70H9Lstb5scmVcEQ_e5n13eUho1IqnX-ho9p98zcFlZd0NvoU)

**於其他設定中，可以設定單個檔案傳的大小限制**

![](https://lh5.googleusercontent.com/wZbVQ0Q4OdumnGvRdQ5N7tTJFbkx7_EHj5eetf7kBLSWAal0rnKrKP1lor7FjHyo2fdA1hBwgFXWTgMA3To9YSVPqJjFqcuW5t_H7xNYB-zt2rIfyak2QWNO25yRk0Gokvnzq1pE)


---

# Agent Instructions: Querying This Documentation

If you need additional information that is not directly available in this page, you can query the documentation dynamically by asking a question.

Perform an HTTP GET request on the current page URL with the `ask` query parameter:

```
GET https://kawsing.gitbook.io/opensystem/docker-cong-an-zhuang-dao-ying-yong-ru-men-pian/shi-yong-dockercompose-zheng-he-mysql.md?ask=<question>
```

The question should be specific, self-contained, and written in natural language.
The response will contain a direct answer to the question and relevant excerpts and sources from the documentation.

Use this mechanism when the answer is not explicitly present in the current page, you need clarification or additional context, or you want to retrieve related documentation sections.
