How to share a common IP between Docker containers

Sometimes you may build your images manually and don’t need something special but something to be used asap.

Such case happened when I wanted to tell php where is the mysql server. Usually after creating and removing containers you may see the mysql container’s ip changed and you have to change the configuration in your site again.

I’ve decided to use one approach that helps me set and forget about the sites’s configuration files and this is using a common IP inside my Docker host that is not 127.0.0.1 or 0.0.0.0.

I’ve made one ifconfig and I’ve seen these lines:

docker0 inet addr:172.17.42.1

lxcbr0 inet addr:10.0.3.1

I just used docker run …… -p 10.0.3.1:3306:3306 …/mysql

Then in the sites’s configs the mysql host was given as 10.0.3.1 instead of 127.0.0.1 or 172.17.0.X

That was since Docker version 0.9.0 went out. I now see only the docker0 ip which still solves the problem the same way with different common IP. I am using libcontainer’s API, no -e lxc, only custom docker data and temp directories set in the defaults file.

How to increase the timeouts when using Nginx, PHP-FPM and phpMyAdmin

Today I needed to change some tables’ structures using phpMyAdmin.

To my surprise not long after I clicked Go to execute the queries, many errors started comming from nginx and php.

So I started looking around about any timeout settings I can use in nginx and php5-fpm and the final working result is this (I choose a timeout of 600 seconds):

/etc/php5/fpm/php.ini

max_execution_time = 600

/etc/php5/fpm/pool.d/www.conf

request_terminate_timeout = 600

in nginx conf of my site inside the *.php location settings:

fastcgi_read_timeout 600;

reload/restart your php and nginx servers for the new changes to take effect and you are ready. Test it by executing some queries that you know will take more time than usual.

Here’s a good source and more settings and information.

If you’re going to change the nginx and php settings of the servers running inside Docker containers you better use this syntax:

servername reload

instead of:

servername restart

Or your container may be automatically stopped after the restart is executes as the restart command is just short for: stop->start.

Cloudflare:

if you’re using phpMyadmin behind Cloudflare, check their thoughts about that: https://support.cloudflare.com/hc/en-us/articles/200171926-Error-524

Find files with the same name in PHPStorm

Just happenned to need a file with the same name but in different subdirs and I needed all occurences. This comes from an old style of developing on a now very busy site and one thing is to continue with the copy/paste or spend a good amount of time replacing the old logic. For now I have minutes to finish and so I started looking at one of the files for a pattern to search as the search is something I use very often and am used to it.

I didn’t pay attention to the Navigation menu in PHPStorm and checked File and Edit then decided to google about my problem and found this one:

http://stackoverflow.com/questions/18372961/how-to-search-a-file-in-phpstorm

Just open Navigate -> File.. and search for the file by its name. Then click the pin button to have it like a regular search result! 🙂