# docker 中下载 mysql
docker pull mysql
#启动
docker run --name mysql -p 3306:3306 -e MYSQL_ROOT_PASSWORD=Lzslov123! -d mysql
#进入容器
docker exec -it mysql bash
#登录mysql
mysql -u root -p
ALTER USER 'root'@'localhost' IDENTIFIED BY 'Lzslov123!';
#添加远程登录用户
CREATE USER 'liaozesong'@'%' IDENTIFIED WITH mysql_native_password BY 'Lzslov123!';
GRANT ALL PRIVILEGES ON *.* TO 'liaozesong'@'%';
The MySQL startup configuration is specified in the file /etc/mysql/my.cnf, and that file in turn includes any files found in the /etc/mysql/conf.d directory that end with .cnf. Settings in files in this directory will augment and/or override settings in /etc/mysql/my.cnf. If you want to use a customized MySQL configuration, you can create your alternative configuration file in a directory on the host machine and then mount that directory location as /etc/mysql/conf.d inside the mysql container.
docker run -p 3307:3306 --name sui-mysql -v /Users/sui/docker/mysql/conf:/etc/mysql -v /Users/sui/docker/mysql/logs:/logs -v /Users/sui/docker/mysql/data:/mysql_data -e MYSQL_ROOT_PASSWORD=123456 -d --link sui-php mysql
进入mysql客户端:
docker run -it --link sui-mysql:mysql --rm mysql sh -c 'exec mysql -h"$MYSQL_PORT_3306_TCP_ADDR" -P"$MYSQL_PORT_3306_TCP_PORT" -uroot -p"$MYSQL_ENV_MYSQL_ROOT_PASSWORD"'
注意:我本地 3306 端口有 mysql, 所以这里用3307端口。
phpmyadmin
docker run --name sui-myadmin -d --link sui-mysql:db -p 8080:80 phpmyadmin/phpmyadmin
2216Windows Docker 安装
docker 安装卡死在 boot2docker.iso 版本一直更新
docker安装需要最新 boot2docker.iso 从docker 网址 < https://github.com/boot2docker/boot2docker/releases/download/v18.09.6/boot2docker.iso 下载好的文件放 文件夹下 docker\machine\cache
1248Docker 安装 MySQL
docker 安装 mysql 8 版本
1247Docker 安装 MySQL
最新官方MySQL(5.7.19)的docker镜像在创建时映射的配置文件目录有所不同,在此记录并分享给大家:
官方原文:
The MySQL startup configuration is specified in the file
/etc/mysql/my.cnf
, and that file in turn includes any files found in the/etc/mysql/conf.d
directory that end with.cnf
. Settings in files in this directory will augment and/or override settings in/etc/mysql/my.cnf
. If you want to use a customized MySQL configuration, you can create your alternative configuration file in a directory on the host machine and then mount that directory location as/etc/mysql/conf.d
inside themysql
container.大概意思是说:
MySQL(5.7.19)的默认配置文件是 /etc/mysql/my.cnf 文件。如果想要自定义配置,建议向 /etc/mysql/conf.d 目录中创建 .cnf 文件。新建的文件可以任意起名,只要保证后缀名是 cnf 即可。新建的文件中的配置项可以覆盖 /etc/mysql/my.cnf 中的配置项。
具体操作:
首先需要创建将要映射到容器中的目录以及.cnf文件,然后再创建容器
命令说明:
查看容器运行情况
1246Docker 安装 PHP
Docker 配置 nginx、php-fpm、mysql
运行环境
创建目录
启动 php-fpm
解释执行 php 需要 php-fpm,先让它运行起来:
--name sui-php 是容器的名字。
/Users/sui/www 是本地 php 文件的存储目录,/var/www/html 是容器内 php 文件的存储目录,ro 表示只读。
编辑 nginx 配置文件
配置文件位置:/Users/sui/docker/nginx/conf.d/default.conf。
说明:
php:9000 表示 php-fpm 服务的访问路径,下文还会提及。
/var/www/html 是 sui-php 中 php 文件的存储路径,经 docker 映射,变成本地路径 /Users/sui/www(可以再看一眼 php-fpm 启动命令
启动 nginx:
-p 80:80 用于添加端口映射,把 sui-nginx 中的 80 端口暴露出来。
/Users/sui/www 是本地 html 文件的存储目录,/usr/share/nginx/html 是容器内 html 文件的存储目录。
/Users/sui/docker/nginx/conf.d 是本地 nginx 配置文件的存储目录,/etc/nginx/conf.d 是容器内 nginx 配置文件的存储目录。
--link sui-php:php 把 sui-php 的网络并入 sui-nginx,并通过修改 sui-nginx 的 /etc/hosts,把域名 php 映射成 127.0.0.1,让 nginx 通过 php:9000 访问 php-fpm。
测试结果
在 /Users/sui/www 下放两个文件:index.html index.php
mysql 和 phpmyadmin
mysql 服务器
进入mysql客户端:
注意:我本地 3306 端口有 mysql, 所以这里用3307端口。
phpmyadmin
大功告成:
1245Docker 安装 Ubuntu Docker 安装
Ubuntu 18.04 安装 Docker-ce
1.更换国内软件源,推荐中国科技大学的源,稳定速度快(可选)
2.安装需要的包
3.添加 GPG 密钥,并添加 Docker-ce 软件源,这里还是以中国科技大学的 Docker-ce 源为例
4.添加成功后更新软件包缓存
5.安装 Docker-ce
6.设置开机自启动并启动 Docker-ce(安装成功后默认已设置并启动,可忽略)
7.测试运行
8.添加当前用户到 docker 用户组,可以不用 sudo 运行 docker(可选)
9.测试添加用户组(可选)