
As of Docker for Mac v1.12.0, there is no need for using my Docker images anymore (although some users still report that my image is the only one working for them). Thanks for the support! You can still use my images if you like. I will be using them and supporting them.
Out-of-the-box MySQL Docker image that *just works* on Mac OS X. Including write support for mounted volumes (MySQL). No matter if using the official boot2docker or having Vagrant in the stack, as well.
osx-docker-mysql, which is known as https://registry.hub.docker.com/u/dgraziotin/mysql/ in the Docker Hub, is a reduced fork of https://github.com/dgraziotin/osx-docker-lamp, which is an "Out-of-the-box LAMP image (PHP+MySQL) for Docker".
Some info about osx-docker-mysql:
CREATE_MYSQL_BASIC_USER_AND_DB="true", it creates a default database and user with permissions to that databaseIf using Vagrant, please see the extra steps in the next subsection.
If you need to create a custom image youruser/mysql,
execute the following command from the osx-docker-mysql source folder:
docker build -t youruser/mysql .
If you wish, you can push your new image to the registry:
docker push youruser/mysql
Otherwise, you are free to use dgraziotin/mysql as it is provided. Remember first to pull it from the Docker Hub:
docker pull dgraziotin/mysql
Warning: I will remove Vagrant support in a coming release
If, for any reason, you would rather use Vagrant (I suggest using https://github.com/AntonioMeireles/boot2docker-vagrant-box), you need to add the following three variables when running your box:
-VAGRANT_OSX_MODE="true" for enabling Vagrant-compatibility
-DOCKER_USER_ID=$(id -u) for letting Vagrant use your host user ID for mounted folders
-DOCKER_USER_GID=$(id -g) for letting Vagrant use your host user GID for mounted folders
See the Environment variables section for more options.
If you start the image without supplying your code, e.g.,
docker run -t -i -p 3306:3306 --name db dgraziotin/mysql
At [boot2docker ip] you should be able to connect to MySQL.
If you wish to mount a MySQL folder locally, so that MySQL files are saved on your OS X machine, run the following instead:
docker run -i -t -p "3306:3306" -v ${PWD}/mysql:/var/lib/mysql --name db dgraziotin/mysql
The MySQL database will thus become persistent at each subsequent run of your image.
MySQL is configured to serve the files from the /mysql folder, which is a symbolic
link to /var/lib/mysql. In osx-docker-mysql, the MySQL user mysql
has full write permissions to the mysql folder.
MySQL runs as user mysql and group staff.
The three MySQL users
The bundled MySQL server has two users, that are root and admin, and an optional
third user user.
The root account comes with an empty password, and it is for local connections
(e.g., using some code). The root user cannot remotely access the database
(and the container).
However, the first time that you run your container, a new user admin
with all root privileges will be created in MySQL with a random password.
To get the password, check the logs of the container by running:
docker logs [name or id, e.g., mywebsite]
You will see an output like the following:
======================================================================== You can now connect to this MySQL Server using: mysql -uadmin -p47nnf4FweaKu -h<host> -P<port> Please remember to change the above password as soon as possible! MySQL user 'root' has no password but only allows local connections ========================================================================
In this case, 47nnf4FweaKu is the password allocated to the admin user.
Finally, an optional a user called user with password password can be created for your convenience either when:
CREATE_MYSQL_BASIC_USER_AND_DB is true; orMYSQL_USER_* variable (explained below) is true
The user is called user and has as password password.The user user has full privileges on a database called db, which is also created
for your convenience. As with the admin user, the user user can access
the MySQL server from any host (%).
The user name, password, and database name can be changed using
the the MYSQL_USER_* variables, explained below.
MYSQL_ADMIN_PASS="mypass" will use your given MySQL password for the admin
user instead of the random one.CREATE_MYSQL_BASIC_USER_AND_DB="true" will create the user user with db db and password password. Not needed if using one of the following three MYSQL_USER_* variablesMYSQL_USER_NAME="daniel" will use your given MySQL username instead of userMYSQL_USER_DB="supercooldb" will use your given database name instead of dbMYSQL_USER_PASS="supersecretpassword" will use your given password instead of password
-VAGRANT_OSX_MODE="true" for enabling Vagrant-compatibility
-DOCKER_USER_ID=$(id -u) for letting Vagrant use your host user ID for mounted folders
-DOCKER_USER_GID=$(id -g) for letting Vagrant use your host user GID for mounted foldersSet these variables using the -e flag when invoking the docker client.
docker run -i -t -p "3306:3306" -e MYSQL_ADMIN_PASS="mypass" --name yourdb dgraziotin/mysql
Please note that the MySQL variables will not work if an existing MySQL volume is supplied.
以下是 dgraziotin/mysql 相关的常用 Docker 镜像,适用于 关系型数据库、事务处理、数据存储 等不同场景:
您可以使用以下命令拉取该镜像。请将 <标签> 替换为具体的标签版本。如需查看所有可用标签版本,请访问 标签列表页面。

探索更多轩辕镜像的使用方法,找到最适合您系统的配置方式
通过 Docker 登录认证访问私有仓库
无需登录使用专属域名
Kubernetes 集群配置 Containerd
K3s 轻量级 Kubernetes 镜像加速
VS Code Dev Containers 配置
Podman 容器引擎配置
HPC 科学计算容器配置
ghcr、Quay、nvcr 等镜像仓库
Harbor Proxy Repository 对接专属域名
Portainer Registries 加速拉取
Nexus3 Docker Proxy 内网缓存
需要其他帮助?请查看我们的 常见问题Docker 镜像访问常见问题解答 或 提交工单
docker search 限制
站内搜不到镜像
离线 save/load
插件要用 plugin install
WSL 拉取慢
安全与 digest
新手拉取配置
镜像合规机制
manifest unknown
no matching manifest(架构)
invalid tar header(解压)
TLS 证书失败
DNS 超时
域名连通性排查
410 Gone 排查
402 与流量用尽
401 认证失败
429 限流
D-Bus 凭证提示
413 与超大单层
来自真实用户的反馈,见证轩辕镜像的优质服务