Take the 2-minute tour ×
Unix & Linux Stack Exchange is a question and answer site for users of Linux, FreeBSD and other Un*x-like operating systems.. It's 100% free, no registration required.

I have to migrate my WordPress installation to my own server in order to get SSL working properly. (It was originally on GoDaddy shared hosting, which doesn't allow for external SSL cert installation.)

Being slightly paranoid and informed about security, I'd like to run the services inside of Docker containers to limit damage in a worst-case scenario.

What I'm not sure of is how to share Docker containers with other Docker containers. If, for example, I have a Docker container responsible for running MySQL/MariaDB, I don't know how I could share that service with another Docker container running FastCGI which is hosting and executing my WordPress PHP code.

My web server (nginx) which is currently running outside of a Docker container won't have any problems proxying things along to an exposed port on a Docker container, but how will the FastCGI server (ie: PHP) be able to reach the MySQL container?

Is there a guide which details how to pair up multiple independent services like this in Docker?

share|improve this question

2 Answers 2

up vote 0 down vote accepted

Actually Docker doesn't do any virtualization, it's just a tool that handles images and uses LXC container virtualization to run them. I guess you're actually looking for LXC and its capabilities, here. LXC can do virtual networking and MySQL can be accessed over the network. The only thing you need is to connect the building blocks together ;).

In a typical setup, each host has its own IP address and set of open ports and each host can access other host's TCP/IP services over the virtual network. Security is handled by the Linux kernel. One way to handle security is the good old iptables based firewall. But there may be other ways based on selinux labeling.

share|improve this answer
    
I'm aware of that. I'm just wondering how I connect one container to another container. For example, if my MySQL container exposes port 41000 to the host operating system, how does the PHP container connect to MySQL at this port? Do all host ports become available to containers? I would assume that host ports would by default not be available to containers in the interest of security. –  Naftuli Tzvi Kay Mar 30 at 19:31
    
Updated. I guess the default will be pretty much open, unless the guest system employs its own security features. –  Pavel Šimerda Mar 30 at 21:34

The way Docker containers work, is that they're isolated by default, unless you set them up otherwise.

To answer your question you can open the ports that you want, and also link containers via these ports, so they only communicate via the port you specify.

When specifying in a Dockerfile, this command is called 'EXPOSE': http://docs.docker.io/reference/builder/#expose

EXPOSE  41000

When starting a container, you can pass the port you want to expose as well, right when it starts up (overrides what may be specified in the original Dockerfile):

sudo docker run -p 41000:41000 -d <your username>/<your image name>

-p, --publish=[] Publish a container's port to the host format: ip:hostPort:containerPort | ip::containerPort | hostPort:containerPort (use 'docker port' to see the actual mapping)

See Linking as well, http://docs.docker.io/use/working_with_links_names/#working-with-links-names


Further reading regarding Wordpress and Docker:

share|improve this answer

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.