Loading... # DockerHub的官方说明 https://hub.docker.com/_/mysql https://hub.docker.com/r/phpmyadmin/phpmyadmin/ # 部署Mysql ```bash docker run --name mysql --restart always -p 13306:3306 \ -v /root/mysql/conf.d:/etc/mysql/conf.d \ -v /root/mysql/data:/var/lib/mysql \ -e MYSQL_ROOT_PASSWORD=123456 \ -d mysql:5.7 ``` > mysql的配置文件:/root/mysql/conf.d:/etc/mysql/conf.d > mysql的存储文件:/root/mysql/data:/var/lib/mysql > mysql的log路径: /root/mysql/logs:/logs > 一般建议写死路径 > 默认密码:-e MYSQL_ROOT_PASSWORD=123456 > 更换端口:-p 13306:3306 # 部署PHPmyadmin ```bash docker run --name phpmyadmin -p 8096:80 -e PMA_PORT=13306 \ --link mysql:db \ -d phpmyadmin/phpmyadmin:latest ``` > 绑定网络:--link mysql:db mysql就是上面容器的名称 > 更换默认端口:-e PMA_PORT=13306 ## 修改phpmyadmin上传附件大小 由于phpmyadmin默认上传附件大小为2M,如果需要迁移数据库,这个肯定是不够的。如果平时的话,直接在php.ini中修改,但是用docker搭建的有点不一样 进入交互界面:`docker exec -it phpmyadmin /bin/bash` 在容器操作系统的/usr/local/etc/php/conf.d下面的所有.ini文件夹下,新建uploads.ini,并写入: ```yml file_uploads = On memory_limit = 64M upload_max_filesize = 64M post_max_size = 64M max_execution_time = 600 ``` **Ctrl+P+Q** 离开交互界面,保存并重启容器即可。 ## docker-compose部署 ```bash version: "3.8" services: db: image: mysql:5.7 restart: always ports: - '13306:3306' volumes: - '/root/mysql/conf.d:/etc/mysql/conf.d' - '/root/mysql/data:/var/lib/mysql' environment: - MYSQL_ROOT_PASSWORD=123456 web: image: phpmyadmin restart: always depends_on: - db ports: - '8096:80' environment: - PMA_PORT=13306 ``` # 使用 如果其他docker需要使用这个mysql,需要确保他们在同一个networks中,比如我搭建了一个yourls的服务,使用这个mysql。 ```bash version: '3.1' services: yourls: image: yourls restart: always ports: - 8039:80 environment: YOURLS_DB_PASS: password YOURLS_DB_HOST: mysql-db-1:3306 YOURLS_DB_USER: yourls YOURLS_SITE: https://i.imgki.com YOURLS_USER: admin YOURLS_PASS: imgki.com networks: default: external: true name: mysql_default ``` `YOURLS_DB_HOST: mysql-db-1:3306`指定使用mysql-db-1,这个是上一个docker-compose启动后的服务名称。 当然也可以使用`docker networks ls`查看网络,在用`docker network inspect mysql_default`查看具体的ip或者名称。 ![mstsc_pka9DnFBe4.png](https://imgki.com/usr/uploads/2023/02/1908104852.png) Last modification:February 22, 2023 © Allow specification reprint Like 如果觉得我的文章对你有用,请随意赞赏