docker-compose搭建wordpress

docker-compose.yml文件

 

version: '3'

services:

  wordpress:
    image: wordpress
    ports:
      - 8080:80
    environment:
      WORDPRESS_DB_HOST: mysql
      WORDPRESS_DB_PASSWORD: root
    networks:
      - my-bridge

  mysql:
    image: mysql
    environment:
      MYSQL_ROOT_PASSWORD: root
      MYSQL_DATABASE: wordpress
    volumes:
      - mysql-data:/var/lib/mysql
    networks:
      - my-bridge

volumes:
  mysql-data:

networks:
  my-bridge:
    driver: bridge
 
 
启动docker-compose
 
docker-compose up
 
浏览器输入宿主机ip,又出现了相同的错误,是的,数据库认证方式的错误
 

解决方法

 
#进入mysql容器
docker-compose exec mysql bash
#登陆数据库
mysql -u root -p
use mysql;
#开启root远程访问权限
grant all on *.* to 'root'@'%';
#修改加密规则
alter user 'root'@'localhost' identified by '123456' password expire never;
#更新密码
alter user 'root'@'%' identified with mysql_native_password by '123456';
#刷新权限
flush privileges;

再次浏览器打开就可以了

posted @ 2019-09-25 14:08  豆浆D  阅读(1455)  评论(0编辑  收藏  举报