Docker Toolbox ではなく Docker for Mac (Docker for Windows)を使う理由は、. $ cd docker-php-nginx-mysql-memcached/docker $ docker-compose up. Nginxの設定ファイルである、nginx.conf、ポートと処理の対応の設定であるserver.conf、nginxとPHP-FPMとの連携の設定である fastcgi.conf. The property was pointing to /var/mysql/mysql.sock but in OSX, the file was. Once I updated the entry in php.ini and restarted the webserver, the issue was.
Abstract
Hello everyone it’s me candle.
In this post I will show you how to connect to the host mysql from the docker container of mac.
In this post I will show you how to connect to the host mysql from the docker container of mac.
For example, you may connect to mysql when running rails, wordpress etc on docker.
You may prepare docker of mysql, but it can’t hold data, it is troublesome such as startup time.
Then I think that it is very useful if docker can access to the host mysql.
You may prepare docker of mysql, but it can’t hold data, it is troublesome such as startup time.
Then I think that it is very useful if docker can access to the host mysql.
Precondition
You use docker for mac
Create mysql database for testing
As a my explain method, this post will explain with a tutorial format.
If you want to know about a important part, skip this chapter and next chapter please.
If you want to know about a important part, skip this chapter and next chapter please.
First let’s create database.
Launch the terminal app and create the file.
Write this to the pokemondb.sql
Load this file.
The database is ready to start.
Create a docker container for testing
In this article, we create nginx and php-fpm container and access host mysql from php.
I almost copied structure of docker from the below site.
The structure is like this.
mysqltest/
├── docker-compose.yml
├── nginx
│ ├── Dockerfile
│ └── server.conf
└── php7
├── Dockerfile
└── index.php
├── docker-compose.yml
├── nginx
│ ├── Dockerfile
│ └── server.conf
└── php7
├── Dockerfile
└── index.php
Execute these commands in a any folder.
Write the below code in the each files.
docker-compose.yml
nginx/Dockerfile
nginx/server.conf
php7/Dockerfile
php7/index.php
The necessary files were prepared.
Add to write.
I will supplement a little.
I will supplement a little.
index.php is important.
It accesses to the host mysql from the docker container.
It accesses to the host mysql from the docker container.
$mysqli = new mysqli(‘10.200.10.1’, ‘root’, ”, ‘pokemondb’);
is
$mysqli = new mysqli(‘host_name’, ‘user_name’, ‘password’, ‘database_name’);
Allocate new local IP address
As you can see from the above index.php code, php is trying to access 10.200.10.1.
However, the lo0 IP address allocated to the host Mac is 127.0.0.1.
However, the lo0 IP address allocated to the host Mac is 127.0.0.1.
Ther problem is that docker can access to the hsot mysql 127.0.0.1
I do not know detail, but it seems that something like that.
I do not know detail, but it seems that something like that.
Then we will add new lo0 IP address 10.200.10.1 to the Mac.
This 10.200.10.1 number was referred to the official docs of docker.
This 10.200.10.1 number was referred to the official docs of docker.
Launch the terminal app of mac and execte this.
Allocate 10.200.10.1 to lo0
Allocate 10.200.10.1 to lo0
After that check it with the below command.
You have to run the command which allocates IP address to the lo0 in every time when you start up Mac PC.
The method of automatically allocating IP is introduced in this article, so please refer to it.
The method of automatically allocating IP is introduced in this article, so please refer to it.
It’s ready.
Lauch docker
Execute this in the folder containing docker-compose.yml exsist
You will check the image when it is over.
Confirm the running container.
Nginx is running in 80 port.
Access URL with browser.
Access URL with browser.
http://127.0.0.1
php has accessed mysql and got data.
Conclusion
It was difficult around the network, and tried and error was made in various ways.