Question

I'm kinda new to Docker and CoreOS. I think I'm just a bit unclear on the concept of containers and how they relate to each other.

I'm trying to set up a CoreOS-based server that runs two services: a custom server (call it myserver), and a memcached server (that will be accessed only by myserver).

So I think I got as far as installing a myserver.service file on the CoreOS machine, that can successfully start upi myserver using a line like this:

ExecStart=/bin/bash -c '/usr/bin/docker start -a my_container || /usr/bin/docker run --name my_container my-image /usr/local/bin/myserver'

So my question is, in order to start up the memcached server, do I create a new memcached.service file in CoreOS? If so, should it use the same container "my_container" as the custom server? If they don't use the same container, will myserver be able to reach the memcached server?

Was it helpful?

Solution

Brooks, Good news. I have an example ( https://github.com/brianredbeard/memcache-tools ) of just that which was written using CoreOS.

In this case you would have two containers with two systemd units.

Memcache.service unit:

[Unit]
Description=My Memcached Server
Requires=docker.service
After=docker.service

[Service]
ExecStart=/usr/bin/docker run --rm --name %n -t -i memcache

Worker.service unit:

[Unit]
Description=My worker container
Requires=Memcache.service
After=Memcache.service

[Service]
ExecStart=/usr/bin/docker run --rm --name %n -t -i --link memcache:memcache my_container

What this will do is take the first container named memcache and present a number of variables into my_container in the form: MEMCAHCE_PORT_11211_TCP_???, e.g.MEMCAHCE_PORT_11211_TCP_HOST & MEMCAHCE_PORT_11211_TCP_PORT which can then be consumed inside your program.

Take a look at the dump, load, and sample scripts as well as the Dockerfile and README.md in that example.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top