3

I have this Dockerfile :

FROM php:5.6-cli
VOLUME /usr/src/up
WORKDIR /usr/src/up
RUN docker-php-source extract \
&& docker-php-ext-install pdo pdo_mysql 
&& docker-php-source delete

RUN echo "date.timezone = Europe/Paris" >> /usr/local/etc/php/php.ini \

This one create a new virtual machine with PHP 5.6, install pdo and pdo_mysql extensions and specify the timezone in php.ini.

The problem that I have is that by default, the virtual machine has a 'NAT network IP address'. Because of that, scripts with FTP connections don't work, I've got this error :

Warning: ftp_get(): I won't open a connection to 172.17.0.2 (only to x.x.x.x)

So I would like my virtual machine has a 'Bridged network IP address', and gets its IP address from my DHCP.

How can I do that ? Could I include that into the Dockerfile in order to facilitate the work for other people ?

Thanks in advance !

Kind regards, Thomas

Toma
  • 97
  • 2
  • 13
  • Not a direct answer to your question; but did you consider using FTP in passive mode (using [`ftp_pasv`](http://php.net/manual/en/function.ftp-pasv.php))? In general, passive FTP should work better behind a NAT gateway. – helmbert Feb 15 '17 at 17:28
  • Yes, but I'm not making the scripts unfortunately, and I can't modify them all the time :( – Toma Feb 15 '17 at 17:36

1 Answers1

5

By default docker server creates a default bridge but you can create your own bridge network and assign your container to that custom bridge on start. Or you can use docker network command which seems to be an easier path. That way you can specify the IP range to match with your DHCP settings.

Create your own bridge

docker network create --driver=bridge \
--subnet=192.168.127.0/24 --gateway=192.168.127.1 \
--ip-range=192.168.127.128/25 yourbridge

Run the container using your custom bridge;

docker run -d --net=yourbridge ..

See this blog post for a concrete example: http://www.dasblinkenlichten.com/docker-networking-101-user-defined-networks/

Within a user-defined bridge network, linking is not supported. You can expose and publish container ports on containers in this network. This is useful if you want to make a portion of the bridge network available to an outside network.

enter image description here

Kerem
  • 2,867
  • 24
  • 35
  • 2
    Thanks a lot for your answer ! :-) I tried to integrate the docker network command into the Dockerfile but apparently it is not the right way to do. Do I have to do it separately from the Dockerfile ? I would like to put the maximum into the Dockerfile in order to simplify the build for other futures users. Thanks in advance, Kind regards Thomas – Toma Feb 16 '17 at 08:32
  • I don't think you can specify network in Dockerfile. But how are you running those docker containers now? You can create a bash script that creates a custom bridge and runs your container hooking it up to the bridge. This does not feel like a default scenario to me for other people though. Have you tried exposing ports with '-p' to external networks before going the long bridge way? Something does not feel right here. – Kerem Feb 16 '17 at 09:01
  • Talking about this https://docs.docker.com/engine/reference/builder/#expose – Kerem Feb 16 '17 at 09:03
  • Could you please elaborate on what worked for you? For other people who end up here. – Kerem Feb 16 '17 at 14:49
  • 1
    Sure. I just did your solution (create the bridge), and put it in a procedure for other people :) Thanks for your help ! – Toma Feb 17 '17 at 08:42