Running as daemon and few more things

Before reading this is important:

I am not criticising docker in any bad way I am just sharing my concerns and questions.

It looks like that only way that I can run docker as daemon is to have some process in infinite loop.
Something like:

/bin/sh -c "while true; do echo hello world; sleep 1; done"

Why docker containers can not be virtual private machines?

I read all of documentation and the thing is, for simple app container docker is great but what if I need little bit more complicated. Let me share few of my thoughts:

  1. Five Apache nodes
  2. Load balancer
  3. Mysql cluster

For 1,2 and 3
If I use haproxy i need static ips for my nodes. I just do not see how to do that with docker since I am getting some docker ips starting with 172. And if I stop/start/restart container that ip is changed. I read about pipework but that works only with linux (there is now way I can test it with OSX since pipework need /proc/mounts and that does not exists on OSX).

In general docker is great but as far as i can see if you need to do some more complicated, that maybe can be done.
With vps I can to apache balancing, mysqc lusters in half and hour.
I am not saying that vps is great.
Maybe I am wrong.

And finally about my question for daemon.

What is the point of running docker if i can not login into running container and do some changes or just to examing apache error logs or what ever. What if I have php app that is not running on port like python web aps (flask or django)? How to run that as deamon? If I do attach, first I can attach only to running containers and if i have some while loop if i attach to that specific container i can only see output of daemon command.

Little more on how questions:
And what about virtual hosts? I i have 10 vhosts in docker container i have to do some iptables in order to forward traffic to boot2docker ip (i have just one ip). What if I want to run 10 containers with apache/ngnix vhosts? How to forward traffic to different containers and finally how to setup dns records in order for that vhosts to work.
probably I need to have some hardware firewall in order to achieve that.

Why not have something like 1 container one ipv4 or ipv6 ip (public or private). That would solve every problem.

Maybe I am expecting to much.
I really would like to hear you opinion.

I got some answers regarding daemons, processes, connecting containers together.

First of all I switched to Supervisor (pip install supervisor) in order to maintain container processes.
Supervisor is great and you do not have to do some dirty hacks in order to run processes.

This is just example how to have apache in one docker container and mysql in other container.
In apache container I have virtual host that use mod_wsgi (it is a python flask app).

  1. I started from git pull debian (i prefer gentoo)

  2. then i make two containers one with python, flask and python mysql driver and other with mysql-server and nothing else

  3. I installed supervisor on both containers

    Apache container supervisor file
    [supervisord]
    nodaemon=true
    user=root
    [program:apache2]
    command=apachectl -D “FOREGROUND” -k start

    Mysql container supervisor file
    [supervisord]
    nodaemon=true
    user=root
    [program:mysqld]
    command=/usr/local/bin/pidproxy /run/mysqld/mysqld.pid /bin/sh -c “exec /usr/bin/mysqld_safe > /dev/null 2>&1 &”

Then I build apache container with:

Docker file
FROM pregmatch/goo.rs
MAINTAINER nikola@pregmatch.org
EXPOSE 80
CMD ["/usr/local/bin/supervisord"]

And mysql container with:

Docker file
FROM pregmatch/goo.rs.db
MAINTAINER nikola@pregmatch.org
EXPOSE 80
CMD ["/usr/local/bin/supervisord"]

Then I started first db container with:

docker run -d --name goorsdb pregmatch/goo.rs.db

And then start web app container aling with link to db container

docker run -d -p 80:80 --name goors --link goorsdb:goorsdb pregmatch/goo.rs

Then I changed in my webapp mysql host to goorsdb (in app configuration) (this host is automaticaly add to /etc/hosts and that is great).

I am logging in (or better said executing /bin/bash) with:

docker exec -ti goors /bin/bash //for web app where goors is my container  name
docker exec -ti goorsdb /bin/bash //for web app where goorsdb is my container  name

In order to exit container without terminate it I am using Ctrl+d.

This is great. Supervisor is great for manage processes.
If you can not figure out how to start process you can always “cat /etc/init.d/someprocess” and copy and paste start/stop line into supervisor.conf file. I put supervisor.conf in /etc/ on both containers.

Virtual host notice: I manually edit /etc/hosts on my laptop (OSX) in order to point domain goo.rs to boot2docker ip.
My guess this can be done like this:

iptables -t nat -A PREROUTING -s [host ip] -p tcp --dport 80 -j DNAT --to-destination [boot2docker ip]:80

I will try to open some blog and to share what I learned on real world examples. I will copy blog url here during next week (it’s a weekend).

That being said. Have a great weekend and I am less frustrated about Docker but all good things take a time to figure out. Will try to do some mysql replication/ mysql cluster next on same app.

Blog url: http://blog.pregmatch.org. I will try to put there lot of Docker related things.

I raised this related topic here:

Yup, this is why we have an example of using Supervisor in the documentation.

for the greatest benefit to all, you could raise pull requests amending of fixing those examples.