docker-compose mysql5.7
时间: 2023-08-18 14:04:58 浏览: 134
要使用docker-compose来部署MySQL 5.7,你可以按照以下步骤进行操作:
1. 首先,确保你已经安装了docker-compose并创建了所需的文件夹。在Linux上,你需要在/usr/local/geek/mysql目录下创建三个文件夹:data(用于存放数据)、conf(存放自定义配置)和log(存放日志文件)。
2. 在mysql文件夹中创建一个名为docker-compose.yml的文件,并将以下内容复制到该文件中:
```
version: '2.2'
services:
mysql:
container_name: mysql
hostname: docker-tool-mysql
cpus: "2"
mem_limit: "2G"
environment:
MYSQL_ROOT_PASSWORD: "123456"
MYSQL_USER: 'zhongtao'
MYSQL_PASS: '123456'
image: "docker.io/mysql:5.7"
restart: always
volumes:
- "/usr/local/geek/mysql/data:/var/lib/mysql"
- "/usr/local/geek/mysql/conf/my.cnf:/etc/my.cnf"
- "/usr/local/geek/mysql/log:/var/log/mysql"
ports:
- "3306:3306"
networks:
20190116_aidata_network:
ipv4_address: 81.68.172.91
networks:
20190116_aidata_network:
external: true
```
3. 保存并关闭docker-compose.yml文件。
4. 在终端中导航到docker-compose.yml所在的目录,然后运行以下命令启动MySQL容器:
```
/usr/local/geek/mysql# docker-compose up -d
```
5. 等待一段时间,MySQL容器将会自动加载和安装。你可以使用以下命令进入MySQL容器内:
```
/usr/local/geek/mysql# docker exec -it mysql bash
```
这样你就可以在MySQL容器中进行操作了。请注意,上述命令中的路径和参数根据你的实际情况进行调整。<span class="em">1</span><span class="em">2</span><span class="em">3</span>
#### 引用[.reference_title]
- *1* *2* *3* [docker-compose安装mysql5.7](https://blog.csdn.net/pichcar1982/article/details/120414471)[target="_blank" data-report-click={"spm":"1018.2226.3001.9630","extra":{"utm_source":"vip_chatgpt_common_search_pc_result","utm_medium":"distribute.pc_search_result.none-task-cask-2~all~insert_cask~default-1-null.142^v92^chatsearchT3_1"}}] [.reference_item style="max-width: 100%"]
[ .reference_list ]
阅读全文