/
data-stores-memcached.html
195 lines (178 loc) · 8.69 KB
/
data-stores-memcached.html
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
<!DOCTYPE html>
<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en-us">
<head>
<link href="http://gmpg.org/xfn/11" rel="profile">
<meta http-equiv="content-type" content="text/html; charset=utf-8">
<!-- Enable responsiveness on mobile devices-->
<meta name="viewport" content="width=device-width, initial-scale=1.0, maximum-scale=1">
<title>
octohost - Simple web focused Docker based mini-PaaS server.
</title>
<!-- CSS -->
<link rel="stylesheet" href="/css/poole.css">
<link rel="stylesheet" href="/css/syntax.css">
<link rel="stylesheet" href="/css/hyde.css">
<link rel="stylesheet" href="/css/octohost.css">
<link rel="stylesheet" href="https://fonts.googleapis.com/css?family=PT+Sans:400,400italic,700|Abril+Fatface">
<script>
(function(i,s,o,g,r,a,m){i['GoogleAnalyticsObject']=r;i[r]=i[r]||function(){
(i[r].q=i[r].q||[]).push(arguments)},i[r].l=1*new Date();a=s.createElement(o),
m=s.getElementsByTagName(o)[0];a.async=1;a.src=g;m.parentNode.insertBefore(a,m)
})(window,document,'script','//www.google-analytics.com/analytics.js','ga');
ga('create', 'UA-12346486-7', 'octohost.io');
ga('send', 'pageview');
</script>
</head>
<body class="theme-base-0g">
<div class="sidebar">
<div class="container sidebar-sticky">
<div class="sidebar-about">
<h1>octohost</h1>
<p class="lead">Simple web focused Docker based mini-PaaS server.</p>
</div>
<div><strong>NOTE:</strong> This project is no longer actively maintained. Use <a href="https://github.com/dokku/dokku">Dokku</a> or <a href="https://github.com/kubernetes/kubernetes">Kubernetes</a>.</div>
<p> </p>
<ul class="sidebar-nav">
<li class="sidebar-nav-item"><a href="/">Home</a></li>
<li class="sidebar-nav-item"><a href="/languages.html">Languages and Frameworks</a></li>
<li class="sidebar-nav-item"><a href="/documentation.html">Documentation</a></li>
<li class="sidebar-nav-item"><a href="/screencast.html">Screencast</a></li>
<li class="sidebar-nav-item"><a href="/changelog.html">Changelog</a></li>
<li class="sidebar-nav-item"><a href="https://twitter.com/octohost">@octohost</a></li>
<li class="sidebar-nav-item"><a href="https://github.com/octohost">Github Project</a></li>
<li class="sidebar-nav-item"><a href="https://index.docker.io/u/octohost/">Docker INDEX</a></li>
</ul>
<p>© 2014 - 2106. All rights reserved.</p>
</div>
</div>
<div class="content container">
<h2>Memcached on octohost</h2><h3>NOTE: Released at 0.8.1.</h3><h4>Please send feedback to <a href="mailto:darron@froese.org">Darron</a></h4><p>Adding a Memcached data store to an octohost website.</p>
<p><em>TLDR: 2 git pushes - 2 linked single use containers.</em></p>
<p>To make this happen, we will utilize 2 containers in total:</p>
<ol>
<li>Memcached application container.</li>
<li>The web application container that is linked to the Memcached application container.</li>
</ol>
<p>We use a simple naming convention to make the linking and volume sharing easier:</p>
<ol>
<li>appname_datastore - for the storage daemon.</li>
<li>appname - for the actual web application that links to the storage daemon.</li>
</ol>
<p>This way - we always know what container name we're looking for when we're linking them up.</p>
<p>Let's add the Memcached application container:</p>
<pre><code>FROM octohost/memcached
ADD memcached.conf /etc/memcached.conf
USER daemon
EXPOSE 11211
# NO_HTTP_PROXY
# ADD_NAME
CMD ["memcached", "-m", "32"]
</code></pre><p>There are a few important commented items at the end of the Dockerfile:</p>
<ol>
<li>Do not add an entry into the HTTP proxy - this won't be accessed from outside the machine.</li>
<li>Add a name <a href="http://docs.docker.io/en/latest/use/working_with_volumes/">so that we can link to this container</a></li>
</ol>
<p>Here's what happens on the push:</p>
<pre><code>[master] darron@~/Dropbox/memcached_container: git remote add dev git@server.octodev.io:test_memcached.git
[master] darron@~/Dropbox/memcached_container: git push dev master
Counting objects: 11, done.
Delta compression using up to 8 threads.
Compressing objects: 100% (11/11), done.
Writing objects: 100% (11/11), 5.60 KiB | 0 bytes/s, done.
Total 11 (delta 2), reused 0 (delta 0)
remote: Put repo in src format somewhere.
remote: Building Docker image.
remote: Base: test_memcached
remote: Nothing running - no need to look for a port.
remote: Uploading context 17.92 kB
remote: Uploading context
remote: Step 0 : FROM octohost/memcached
remote: ---> cdbca89ea78d
remote: Step 1 : ADD memcached.conf /etc/memcached.conf
remote: ---> Using cache
remote: ---> fca182755319
remote: Step 2 : USER daemon
remote: ---> Using cache
remote: ---> c39fbd0799d1
remote: Step 3 : EXPOSE 11211
remote: ---> Running in b8559f8343bc
remote: ---> b08edf25611d
remote: Step 4 : CMD ["memcached", "-m", "32"]
remote: ---> Running in 6493002c4ebc
remote: ---> 6ca0d81c2ad9
remote: Successfully built 6ca0d81c2ad9
remote: Port: 49155
To git@server.octodev.io:test_memcached.git
* [new branch] master -> master
</code></pre><p>We've provisioned a Memcached server and it's ready to go.</p>
<p>Now let's link up the final application container - here's the Dockerfile:</p>
<pre><code> FROM octohost/ruby-1.9
RUN apt-get update && apt-get install -y libsasl2-dev
ADD . /srv/www
RUN cd /srv/www; bundle install --deployment --without test development
# LINK_SERVICE memcached
EXPOSE 5000
CMD ["/usr/local/bin/foreman","start","-d","/srv/www"]
</code></pre><p>There's only 1 special comment in this Dockerfile - on push, octohost links this container to the Memcached container we created in step 2. Let's try it:</p>
<pre><code> [master] darron@~/Dropbox/memcached_app: git push dev master
Warning: remote port forwarding failed for listen port 52698
Counting objects: 5, done.
Delta compression using up to 8 threads.
Compressing objects: 100% (3/3), done.
Writing objects: 100% (3/3), 318 bytes | 0 bytes/s, done.
Total 3 (delta 2), reused 0 (delta 0)
remote: Put repo in src format somewhere.
remote: Building Docker image.
remote: Base: test
remote: Uploading context 10.24 kB
remote: Uploading context
remote: Step 0 : FROM octohost/ruby-1.9
remote: ---> 9bc0da4bad25
remote: Step 1 : RUN apt-get update && apt-get install -y libsasl2-dev
remote: ---> Using cache
remote: ---> db5ea094e329
remote: Step 2 : ADD . /srv/www
remote: ---> 382721008aba
remote: Step 3 : RUN cd /srv/www; bundle install --deployment --without test development
remote: ---> Running in 2662ae1560c2
remote: Fetching gem metadata from https://rubygems.org/.........
remote: Fetching gem metadata from https://rubygems.org/..
remote: Installing dotenv (0.9.0)
remote: Installing thor (0.18.1)
remote: Installing foreman (0.63.0)
remote: Installing memcached (1.7.2)
remote: Installing rack (1.5.2)
remote: Installing rack-protection (1.5.2)
remote: Installing tilt (1.4.1)
remote: Installing sinatra (1.4.4)
remote: Using bundler (1.3.5)
remote: Your bundle is complete!
remote: Gems in the groups test and development were not installed.
remote: It was installed into ./vendor/bundle
remote: ---> 459da9d79a5e
remote: Step 4 : EXPOSE 5000
remote: ---> Running in b8a147738fda
remote: ---> db690947717e
remote: Step 5 : CMD ["/usr/local/bin/foreman","start","-d","/srv/www"]
remote: ---> Running in 75aa6737640b
remote: ---> a44ac63898e6
remote: Successfully built a44ac63898e6
remote: Linking to: test_memcached:memcached
remote: Adding http://test.192.168.62.86.xip.io
remote: Adding http://test.octodev.io
remote: Your site is available at: http://test.192.168.62.86.xip.io
remote: Your site is available at: http://test.octodev.io
To git@server.octodev.io:test.git
* [new branch] master -> master
</code></pre><p>And that's it.</p>
<p>2 pushes - 2 containers:</p>
<ol>
<li><a href="https://github.com/octohost/memcached_container">Memcached container running.</a></li>
<li><a href="https://github.com/octohost/memcached_app">Small Sinatra app linked to the Memcached container.</a></li>
</ol>
<p>Take a look at the Sinatra code here: <a href="https://github.com/octohost/memcached_app">https://github.com/octohost/memcached_app</a></p>
<p>Send us an email at <a href="mailto:octohost@octohost.io">octohost@octohost.io</a>. Follow us on Twitter <a href="https://twitter.com/octohost">@octohost</a>.</p>
<div class="src"><a href="https://github.com/octohost/www">Website source.</a></div>
</div>
</body>
</html>