Breaking Things Out into Docker Containers

43 views
Skip to first unread message

Jamie Jackson

unread,
Mar 25, 2016, 4:17:54 PM3/25/16
to vagra...@googlegroups.com
[I really need to have a real-time conversation with someone, but unfortunately, I've never had any luck getting responses on #vagrant in freenode (lots of lurkers, but no participants), so email will have to do.]

I have got a Vagrant configuration that creates local development environments for our team. (I haven't dealt with creating my own distributed boxes. On first Vagrant up, everybody starts with the generic ubuntu/precise64 and waits about 10 minutes for it to get provisioned.)

FWIW, the environment has:
  • Apache HTTP
  • Lucee (Web Application Server)
  • MariaDB
  • Various development utils (e.g., MailCatcher)
Recently, I've had a need to add a GlassFish server to the mix, so I provisioned it to the same VM as above, along with all of the existing provisioners. (Side note, all provisioners are shell scripts, so far, I haven't ventured into sophisticated provisioners yet, FYI.)

However, I think I'd like to revert GlassFish out of that VM configuration and stand it up in Docker, instead, both to get more exposure to Docker and to take a step toward DevOps for servers.

The idea is that I'd still manage this whole cluster of services with one Vagrantfile, and while I'd leave the old stack on the vbox provider for now, I'd just have that Docker container for Glassfish. (I guess that would mean that the VM would become a Docker host, as well.) Eventually, I think I'd also want to move some of those other services to containers, too.

Is this feasible/sane?

If so, I could use some nuts and bolts help in getting going with this. I've been reading about Vagrant/Docker integration for a couple days now, but the examples (on blogs, etc.) were either broken or (for me, as a Docker noob) hard to adapt.

Thanks,
Jamie

Vince Skahan

unread,
Mar 25, 2016, 7:21:18 PM3/25/16
to Vagrant
this help any as an example ?

(google search for 'vagrant docker example' returns loads of good info)


Jamie Jackson

unread,
Mar 30, 2016, 10:42:59 AM3/30/16
to vagra...@googlegroups.com
First tangent: Given the example that you linked, how would I modify the configurations to access nginx (on port 80) from the vbox host (physical machine)? As that example stands, I end up with the following in the docker host VM:

docker0   Link encap:Ethernet 
          inet addr:172.17.0.1  Bcast:0.0.0.0  Mask:255.255.0.0
          inet6 addr: fe80::42:c7ff:fe28:1d4f/64 Scope:Link

eth0      Link encap:Ethernet
          inet addr:10.0.2.15  Bcast:10.0.2.255  Mask:255.255.255.0
          inet6 addr: fe80::a00:27ff:fe08:9d5f/64 Scope:Link
          UP BROADCAST RUNNING MULTICAST  MTU:1500  Metric:1
          RX packets:161354 errors:0 dropped:0 overruns:0 frame:0
          TX packets:56006 errors:0 dropped:0 overruns:0 carrier:0
          collisions:0 txqueuelen:1000
          RX bytes:131353816 (131.3 MB)  TX bytes:3758324 (3.7 MB)

lo        Link encap:Local Loopback
          inet addr:127.0.0.1  Mask:255.0.0.0
          inet6 addr: ::1/128 Scope:Host

veth01495d8 Link encap:Ethernet
          inet6 addr: fe80::e8a1:15ff:fecc:f646/64 Scope:Link

And within the docker host VM, I can see the nginx welcome screen with any of the following:
  1. lynx 172.17.0.1
  2. lynx 10.0.2.15
  3. lynx 127.0.0.1
However, 1 and 2 don't work from the physical host.

(FWIW, I have "ubuntu/trusty64" instead of "slowe/ubuntu-trusty-x64" in the host Vagrantfile, though I don't remember now why I made that switch.)

How do I enable access to nginx? (I prefer accessing guest ports on the guest IPs, rather than forwarding the ports to localhost on my physical box.)

Thanks,
Jamie


--
This mailing list is governed under the HashiCorp Community Guidelines - https://www.hashicorp.com/community-guidelines.html. Behavior in violation of those guidelines may result in your removal from this mailing list.
 
GitHub Issues: https://github.com/mitchellh/vagrant/issues
IRC: #vagrant on Freenode
---
You received this message because you are subscribed to the Google Groups "Vagrant" group.
To unsubscribe from this group and stop receiving emails from it, send an email to vagrant-up+...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/vagrant-up/b5d6e999-95da-4adf-874a-aed62b5e200c%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

Alvaro Miranda Aguilera

unread,
Mar 30, 2016, 11:01:35 PM3/30/16
to vagra...@googlegroups.com
Hello Jamie, long time.

You need to do something like this:

host -> vm -> docker

on the container you can use

d.ports = ["8080:80"]

so on the VM you can use

config.vm.network :forwarded_port, guest: 8080, host: 8080

Then on the host you can use http://localhost:8080 and that will go to the container.

Let me know if this helps, or is still too high level.

Alvaro.


Jamie Jackson

unread,
Mar 31, 2016, 9:29:38 AM3/31/16
to vagra...@googlegroups.com
Hi Alvaro,

Port forwarding from the VM to the host would work, but I prefer to reach my boxes directly. I forgot that I had to set up a private network to do this, but I remembered when I came back to it this morning.

  config.vm.network "private_network", type: "dhcp" # or static IP

That gets me what I need. I'll continue to play with this example.

Thanks,
Jamie

Reply all
Reply to author
Forward
0 new messages