SlideShare a Scribd company logo
1 of 10
Download to read offline
Install and Run Memcached as a service using docker on your server




                                                 Install and Run
           Memcached as a service
                                                      using docker



Table of Contents
Requirements................................................................................................................................................ 2
Installing Memcached on Docker ................................................................................................................. 3
   Check for docker daemon ......................................................................................................................... 3
   Installing Memcached ............................................................................................................................... 3
   Commit your new container ..................................................................................................................... 4
Running and using Memcached on Docker .................................................................................................. 5
   Running Memcached on Docker ............................................................................................................... 6
   Using Memcached..................................................................................................................................... 6
   Testing Memcached service...................................................................................................................... 8
       Testing with Ruby.................................................................................................................................. 8
       Testing with Python .............................................................................................................................. 8
       Testing with PHP ................................................................................................................................... 9
       Testing with Go ..................................................................................................................................... 9




http://www.slideshare.net/julienbarbier42/memcached-as-a-service-using-docker
Install and Run Memcached as a service using docker on your server



Requirements

   1. Install last version of docker on your Operating System

Please visit http://www.docker.io/gettingstarted/ to get docker installed on your Ubuntu or
using Vagrant + VirtualBox on any other Operating system

   2. Make sure you are running docker as a daemon. If it is not the case you can launch
      docker daemon by running

sudo docker –d &




http://www.slideshare.net/julienbarbier42/memcached-as-a-service-using-docker
Install and Run Memcached as a service using docker on your server



Installing Memcached on Docker


Check for docker daemon

Before starting, make sure docker is running as a daemon on your system. If it is not the
case, please read the “Requirements” Section.

ps aux | grep docker




You should see a line with docker –d


Installing Memcached

docker run -d base apt-get -y install memcached




This will give you the id of the new created container running your command apt-get. You
will need to keep this id in order to use it later. In our example, the id is f1ab59fbc9d5

We can check that the installation is completed by using the docker logs command
docker logs f1ab59fbc9d5 | less

Remember to replace f1ab59fbc9d5 by your id before running this command.




http://www.slideshare.net/julienbarbier42/memcached-as-a-service-using-docker
Install and Run Memcached as a service using docker on your server




Commit your new container

We can commit our new container with the docker commit command, using our id.

docker commit f1ab59fbc9d5 jbarbier/memcached

Remember to replace f1ab59fbc9d5 by your id before running this command. You can
also replace jbarbier/memcached with your own repository name.




http://www.slideshare.net/julienbarbier42/memcached-as-a-service-using-docker
Install and Run Memcached as a service using docker on your server




This command gives you a new id which is the image id of your container. In our example
it is c3b6fcb48266. Note that id so we can use it later.

Let’s check that Memcached is installed on this image. To do so we can spawn a new
container from this image and run bash inside.

docker run -i -t jbarbier/memcached /bin/bash

Remember to replace jbarbier/memcached by your repository name before running this
command.




We are now inside a container spawned from our image. Let’s see if Memcached is
installed

memcached




OK!

Note that you could have used the id of your image instead of the name of your repository.

docker run -i -t c3b6fcb48266 /bin/bash

Remember to replace c3b6fcb48266 by your image id before running this command.




Running and using Memcached on Docker

Now that we have an image with Memcached installed, let’s use it :)


http://www.slideshare.net/julienbarbier42/memcached-as-a-service-using-docker
Install and Run Memcached as a service using docker on your server




Running Memcached on Docker

docker run -d -p 11211 jbarbier/memcached memcached -u daemon

Remember to replace jbarbier/memcached by your repository name before running this
command.

We need the –u option because Memcache can not run as root.

In order to be able to use Memcached from outside our server, we canuse the –p 11211
option, which will ask docker to map the internal port of the container used by Memcached
(11211), with a public port of the host.




As usual, docker gives you back the id of the container you launched. In our case it is
c360f228e22f. Note that id in order to use it later.


Using Memcached

In order to use Memcached from outside the localhost we need to know the host public
port mapped by docker. In order to know that we can use the docker inspect command.

docker inspect c360f228e22f

Remember to replace c360f228e22f by your container id before running this command.

This will give you a JSON output with plenty of configuration details. In the
NetworkSettings/PortMapping you will find the public port you can use Memcached with
from outside your server.




http://www.slideshare.net/julienbarbier42/memcached-as-a-service-using-docker
Install and Run Memcached as a service using docker on your server




http://www.slideshare.net/julienbarbier42/memcached-as-a-service-using-docker
Install and Run Memcached as a service using docker on your server




In our case the public port is 49153.


Testing Memcached service

Let’s test and use our Memcached service, from an outside machine. In the following
examples I will use 142.242.242.42 as the IP of the server where the container is running,
and 49153 as the public port.

Before running any of these examples be sure to replace the IP with your server IP, and
the port number with the one docker inspect gave you.


Testing with Ruby

Guillotine:test_memcached jbarbier$ cat test.rb
# run gem install dalli first

require 'dalli'

ip = '142.242.242.42'
port = 49153

dc = Dalli::Client.new("#{ip}:#{port}")
dc.set('abc', "Always Be Closing")
value = dc.get('abc')

puts value

ruby test.rb




Testing with Python

Guillotine:test_memcached jbarbier$ cat test.py
# pip install python-memcached if import memcache fails

import memcache

ip = '142.242.242.42'
port = 49153

mc = memcache.Client(["{0}:{1}".format(ip, port)], debug=0)


http://www.slideshare.net/julienbarbier42/memcached-as-a-service-using-docker
Install and Run Memcached as a service using docker on your server




mc.set("best_dev", "Guillaume C.")
value = mc.get("best_dev")

print value

python test.py




Testing with PHP

Guillotine:test_memcached jbarbier$ cat test.php
<?php

$ip = '142.242.242.42';
$port = 49153;

$memcache_obj = new Memcache;
$memcache_obj->connect($ip, $port);

$memcache_obj->set('rule_1', 'You DO NOT talk about FIGHT CLUB');
$v = $memcache_obj->get('rule_1');

echo "$vn";

?>

php test.php




Testing with Go

Guillotine:test_memcached jbarbier$ cat test.go
package main

import (
"fmt"
"github.com/kklis/gomemcache"
)



http://www.slideshare.net/julienbarbier42/memcached-as-a-service-using-docker
Install and Run Memcached as a service using docker on your server




func main() {

ip := "142.242.242.42"
port := 49153

memc, err := gomemcache.Connect(ip, port)
if err != nil {
panic(err)
}
err = memc.Set("foo", []byte("bar"), 0, 0)
if err != nil {
panic(err)
}
val, _, _ := memc.Get("foo")
fmt.Printf("%sn", val)
}

Go run test.go




http://www.slideshare.net/julienbarbier42/memcached-as-a-service-using-docker

More Related Content

Viewers also liked

A Gentle Introduction To Docker And All Things Containers
A Gentle Introduction To Docker And All Things ContainersA Gentle Introduction To Docker And All Things Containers
A Gentle Introduction To Docker And All Things ContainersJérôme Petazzoni
 
Docker Online Meetup: Announcing Docker CE + EE
Docker Online Meetup: Announcing Docker CE + EEDocker Online Meetup: Announcing Docker CE + EE
Docker Online Meetup: Announcing Docker CE + EEDocker, Inc.
 
Docker 101 - Nov 2016
Docker 101 - Nov 2016Docker 101 - Nov 2016
Docker 101 - Nov 2016Docker, Inc.
 
Docker introduction
Docker introductionDocker introduction
Docker introductiondotCloud
 
containerd and CRI
containerd and CRIcontainerd and CRI
containerd and CRIDocker, Inc.
 
Docker 101: Introduction to Docker
Docker 101: Introduction to DockerDocker 101: Introduction to Docker
Docker 101: Introduction to DockerDocker, Inc.
 
Docker入門: コンテナ型仮想化技術の仕組みと使い方
Docker入門: コンテナ型仮想化技術の仕組みと使い方Docker入門: コンテナ型仮想化技術の仕組みと使い方
Docker入門: コンテナ型仮想化技術の仕組みと使い方Yuichi Ito
 

Viewers also liked (11)

DevOps
DevOpsDevOps
DevOps
 
A Gentle Introduction To Docker And All Things Containers
A Gentle Introduction To Docker And All Things ContainersA Gentle Introduction To Docker And All Things Containers
A Gentle Introduction To Docker And All Things Containers
 
Introducing DevOps
Introducing DevOpsIntroducing DevOps
Introducing DevOps
 
DevOps 101
DevOps 101DevOps 101
DevOps 101
 
Docker by Example - Basics
Docker by Example - Basics Docker by Example - Basics
Docker by Example - Basics
 
Docker Online Meetup: Announcing Docker CE + EE
Docker Online Meetup: Announcing Docker CE + EEDocker Online Meetup: Announcing Docker CE + EE
Docker Online Meetup: Announcing Docker CE + EE
 
Docker 101 - Nov 2016
Docker 101 - Nov 2016Docker 101 - Nov 2016
Docker 101 - Nov 2016
 
Docker introduction
Docker introductionDocker introduction
Docker introduction
 
containerd and CRI
containerd and CRIcontainerd and CRI
containerd and CRI
 
Docker 101: Introduction to Docker
Docker 101: Introduction to DockerDocker 101: Introduction to Docker
Docker 101: Introduction to Docker
 
Docker入門: コンテナ型仮想化技術の仕組みと使い方
Docker入門: コンテナ型仮想化技術の仕組みと使い方Docker入門: コンテナ型仮想化技術の仕組みと使い方
Docker入門: コンテナ型仮想化技術の仕組みと使い方
 

More from Julien Barbier

Community Marketing at Docker | Docker Tour de France 2014
Community Marketing at Docker | Docker Tour de France 2014Community Marketing at Docker | Docker Tour de France 2014
Community Marketing at Docker | Docker Tour de France 2014Julien Barbier
 
Docker, the Future of Distributed Applications | Docker Tour de France 2014
Docker, the Future of Distributed Applications | Docker Tour de France 2014Docker, the Future of Distributed Applications | Docker Tour de France 2014
Docker, the Future of Distributed Applications | Docker Tour de France 2014Julien Barbier
 
Growth hacking | Workshop at Epitech
Growth hacking | Workshop at EpitechGrowth hacking | Workshop at Epitech
Growth hacking | Workshop at EpitechJulien Barbier
 
Intro Docker to Loire Atlantique
Intro Docker to Loire AtlantiqueIntro Docker to Loire Atlantique
Intro Docker to Loire AtlantiqueJulien Barbier
 
Marketing & Community at Docker (30-min presentation to Trinity Ventures' por...
Marketing & Community at Docker (30-min presentation to Trinity Ventures' por...Marketing & Community at Docker (30-min presentation to Trinity Ventures' por...
Marketing & Community at Docker (30-min presentation to Trinity Ventures' por...Julien Barbier
 
Docker & Growth Hacking presentation at UBI I/O - San Francisco
Docker & Growth Hacking presentation at UBI I/O - San FranciscoDocker & Growth Hacking presentation at UBI I/O - San Francisco
Docker & Growth Hacking presentation at UBI I/O - San FranciscoJulien Barbier
 
while42 SF #12 - Selected Side Projects
while42 SF #12 - Selected Side Projectswhile42 SF #12 - Selected Side Projects
while42 SF #12 - Selected Side ProjectsJulien Barbier
 
Docker - 15 great Tutorials
Docker - 15 great TutorialsDocker - 15 great Tutorials
Docker - 15 great TutorialsJulien Barbier
 
Run Docker On Windows Using Vagrant
Run Docker On Windows Using VagrantRun Docker On Windows Using Vagrant
Run Docker On Windows Using VagrantJulien Barbier
 
Who wants to be an entrepreneur @ European Institute of Technology
Who wants to be an entrepreneur @ European Institute of TechnologyWho wants to be an entrepreneur @ European Institute of Technology
Who wants to be an entrepreneur @ European Institute of TechnologyJulien Barbier
 
Notions juridiques internet - Support de conférence @ European Institute of T...
Notions juridiques internet - Support de conférence @ European Institute of T...Notions juridiques internet - Support de conférence @ European Institute of T...
Notions juridiques internet - Support de conférence @ European Institute of T...Julien Barbier
 

More from Julien Barbier (14)

Community Marketing at Docker | Docker Tour de France 2014
Community Marketing at Docker | Docker Tour de France 2014Community Marketing at Docker | Docker Tour de France 2014
Community Marketing at Docker | Docker Tour de France 2014
 
Docker, the Future of Distributed Applications | Docker Tour de France 2014
Docker, the Future of Distributed Applications | Docker Tour de France 2014Docker, the Future of Distributed Applications | Docker Tour de France 2014
Docker, the Future of Distributed Applications | Docker Tour de France 2014
 
Marketing for Hackers
Marketing for HackersMarketing for Hackers
Marketing for Hackers
 
Community Marketing
Community MarketingCommunity Marketing
Community Marketing
 
Growth hacking | Workshop at Epitech
Growth hacking | Workshop at EpitechGrowth hacking | Workshop at Epitech
Growth hacking | Workshop at Epitech
 
Intro Docker to Loire Atlantique
Intro Docker to Loire AtlantiqueIntro Docker to Loire Atlantique
Intro Docker to Loire Atlantique
 
Community at Docker
Community at DockerCommunity at Docker
Community at Docker
 
Marketing & Community at Docker (30-min presentation to Trinity Ventures' por...
Marketing & Community at Docker (30-min presentation to Trinity Ventures' por...Marketing & Community at Docker (30-min presentation to Trinity Ventures' por...
Marketing & Community at Docker (30-min presentation to Trinity Ventures' por...
 
Docker & Growth Hacking presentation at UBI I/O - San Francisco
Docker & Growth Hacking presentation at UBI I/O - San FranciscoDocker & Growth Hacking presentation at UBI I/O - San Francisco
Docker & Growth Hacking presentation at UBI I/O - San Francisco
 
while42 SF #12 - Selected Side Projects
while42 SF #12 - Selected Side Projectswhile42 SF #12 - Selected Side Projects
while42 SF #12 - Selected Side Projects
 
Docker - 15 great Tutorials
Docker - 15 great TutorialsDocker - 15 great Tutorials
Docker - 15 great Tutorials
 
Run Docker On Windows Using Vagrant
Run Docker On Windows Using VagrantRun Docker On Windows Using Vagrant
Run Docker On Windows Using Vagrant
 
Who wants to be an entrepreneur @ European Institute of Technology
Who wants to be an entrepreneur @ European Institute of TechnologyWho wants to be an entrepreneur @ European Institute of Technology
Who wants to be an entrepreneur @ European Institute of Technology
 
Notions juridiques internet - Support de conférence @ European Institute of T...
Notions juridiques internet - Support de conférence @ European Institute of T...Notions juridiques internet - Support de conférence @ European Institute of T...
Notions juridiques internet - Support de conférence @ European Institute of T...
 

Recently uploaded

SALESFORCE EDUCATION CLOUD | FEXLE SERVICES
SALESFORCE EDUCATION CLOUD | FEXLE SERVICESSALESFORCE EDUCATION CLOUD | FEXLE SERVICES
SALESFORCE EDUCATION CLOUD | FEXLE SERVICESmohitsingh558521
 
Merck Moving Beyond Passwords: FIDO Paris Seminar.pptx
Merck Moving Beyond Passwords: FIDO Paris Seminar.pptxMerck Moving Beyond Passwords: FIDO Paris Seminar.pptx
Merck Moving Beyond Passwords: FIDO Paris Seminar.pptxLoriGlavin3
 
"ML in Production",Oleksandr Bagan
"ML in Production",Oleksandr Bagan"ML in Production",Oleksandr Bagan
"ML in Production",Oleksandr BaganFwdays
 
Ensuring Technical Readiness For Copilot in Microsoft 365
Ensuring Technical Readiness For Copilot in Microsoft 365Ensuring Technical Readiness For Copilot in Microsoft 365
Ensuring Technical Readiness For Copilot in Microsoft 3652toLead Limited
 
Use of FIDO in the Payments and Identity Landscape: FIDO Paris Seminar.pptx
Use of FIDO in the Payments and Identity Landscape: FIDO Paris Seminar.pptxUse of FIDO in the Payments and Identity Landscape: FIDO Paris Seminar.pptx
Use of FIDO in the Payments and Identity Landscape: FIDO Paris Seminar.pptxLoriGlavin3
 
SIP trunking in Janus @ Kamailio World 2024
SIP trunking in Janus @ Kamailio World 2024SIP trunking in Janus @ Kamailio World 2024
SIP trunking in Janus @ Kamailio World 2024Lorenzo Miniero
 
The Fit for Passkeys for Employee and Consumer Sign-ins: FIDO Paris Seminar.pptx
The Fit for Passkeys for Employee and Consumer Sign-ins: FIDO Paris Seminar.pptxThe Fit for Passkeys for Employee and Consumer Sign-ins: FIDO Paris Seminar.pptx
The Fit for Passkeys for Employee and Consumer Sign-ins: FIDO Paris Seminar.pptxLoriGlavin3
 
Scanning the Internet for External Cloud Exposures via SSL Certs
Scanning the Internet for External Cloud Exposures via SSL CertsScanning the Internet for External Cloud Exposures via SSL Certs
Scanning the Internet for External Cloud Exposures via SSL CertsRizwan Syed
 
How AI, OpenAI, and ChatGPT impact business and software.
How AI, OpenAI, and ChatGPT impact business and software.How AI, OpenAI, and ChatGPT impact business and software.
How AI, OpenAI, and ChatGPT impact business and software.Curtis Poe
 
The State of Passkeys with FIDO Alliance.pptx
The State of Passkeys with FIDO Alliance.pptxThe State of Passkeys with FIDO Alliance.pptx
The State of Passkeys with FIDO Alliance.pptxLoriGlavin3
 
DSPy a system for AI to Write Prompts and Do Fine Tuning
DSPy a system for AI to Write Prompts and Do Fine TuningDSPy a system for AI to Write Prompts and Do Fine Tuning
DSPy a system for AI to Write Prompts and Do Fine TuningLars Bell
 
WordPress Websites for Engineers: Elevate Your Brand
WordPress Websites for Engineers: Elevate Your BrandWordPress Websites for Engineers: Elevate Your Brand
WordPress Websites for Engineers: Elevate Your Brandgvaughan
 
Developer Data Modeling Mistakes: From Postgres to NoSQL
Developer Data Modeling Mistakes: From Postgres to NoSQLDeveloper Data Modeling Mistakes: From Postgres to NoSQL
Developer Data Modeling Mistakes: From Postgres to NoSQLScyllaDB
 
Gen AI in Business - Global Trends Report 2024.pdf
Gen AI in Business - Global Trends Report 2024.pdfGen AI in Business - Global Trends Report 2024.pdf
Gen AI in Business - Global Trends Report 2024.pdfAddepto
 
Passkey Providers and Enabling Portability: FIDO Paris Seminar.pptx
Passkey Providers and Enabling Portability: FIDO Paris Seminar.pptxPasskey Providers and Enabling Portability: FIDO Paris Seminar.pptx
Passkey Providers and Enabling Portability: FIDO Paris Seminar.pptxLoriGlavin3
 
New from BookNet Canada for 2024: Loan Stars - Tech Forum 2024
New from BookNet Canada for 2024: Loan Stars - Tech Forum 2024New from BookNet Canada for 2024: Loan Stars - Tech Forum 2024
New from BookNet Canada for 2024: Loan Stars - Tech Forum 2024BookNet Canada
 
Unleash Your Potential - Namagunga Girls Coding Club
Unleash Your Potential - Namagunga Girls Coding ClubUnleash Your Potential - Namagunga Girls Coding Club
Unleash Your Potential - Namagunga Girls Coding ClubKalema Edgar
 
Streamlining Python Development: A Guide to a Modern Project Setup
Streamlining Python Development: A Guide to a Modern Project SetupStreamlining Python Development: A Guide to a Modern Project Setup
Streamlining Python Development: A Guide to a Modern Project SetupFlorian Wilhelm
 
Moving Beyond Passwords: FIDO Paris Seminar.pdf
Moving Beyond Passwords: FIDO Paris Seminar.pdfMoving Beyond Passwords: FIDO Paris Seminar.pdf
Moving Beyond Passwords: FIDO Paris Seminar.pdfLoriGlavin3
 

Recently uploaded (20)

SALESFORCE EDUCATION CLOUD | FEXLE SERVICES
SALESFORCE EDUCATION CLOUD | FEXLE SERVICESSALESFORCE EDUCATION CLOUD | FEXLE SERVICES
SALESFORCE EDUCATION CLOUD | FEXLE SERVICES
 
Merck Moving Beyond Passwords: FIDO Paris Seminar.pptx
Merck Moving Beyond Passwords: FIDO Paris Seminar.pptxMerck Moving Beyond Passwords: FIDO Paris Seminar.pptx
Merck Moving Beyond Passwords: FIDO Paris Seminar.pptx
 
"ML in Production",Oleksandr Bagan
"ML in Production",Oleksandr Bagan"ML in Production",Oleksandr Bagan
"ML in Production",Oleksandr Bagan
 
Ensuring Technical Readiness For Copilot in Microsoft 365
Ensuring Technical Readiness For Copilot in Microsoft 365Ensuring Technical Readiness For Copilot in Microsoft 365
Ensuring Technical Readiness For Copilot in Microsoft 365
 
Use of FIDO in the Payments and Identity Landscape: FIDO Paris Seminar.pptx
Use of FIDO in the Payments and Identity Landscape: FIDO Paris Seminar.pptxUse of FIDO in the Payments and Identity Landscape: FIDO Paris Seminar.pptx
Use of FIDO in the Payments and Identity Landscape: FIDO Paris Seminar.pptx
 
SIP trunking in Janus @ Kamailio World 2024
SIP trunking in Janus @ Kamailio World 2024SIP trunking in Janus @ Kamailio World 2024
SIP trunking in Janus @ Kamailio World 2024
 
The Fit for Passkeys for Employee and Consumer Sign-ins: FIDO Paris Seminar.pptx
The Fit for Passkeys for Employee and Consumer Sign-ins: FIDO Paris Seminar.pptxThe Fit for Passkeys for Employee and Consumer Sign-ins: FIDO Paris Seminar.pptx
The Fit for Passkeys for Employee and Consumer Sign-ins: FIDO Paris Seminar.pptx
 
Scanning the Internet for External Cloud Exposures via SSL Certs
Scanning the Internet for External Cloud Exposures via SSL CertsScanning the Internet for External Cloud Exposures via SSL Certs
Scanning the Internet for External Cloud Exposures via SSL Certs
 
How AI, OpenAI, and ChatGPT impact business and software.
How AI, OpenAI, and ChatGPT impact business and software.How AI, OpenAI, and ChatGPT impact business and software.
How AI, OpenAI, and ChatGPT impact business and software.
 
The State of Passkeys with FIDO Alliance.pptx
The State of Passkeys with FIDO Alliance.pptxThe State of Passkeys with FIDO Alliance.pptx
The State of Passkeys with FIDO Alliance.pptx
 
DMCC Future of Trade Web3 - Special Edition
DMCC Future of Trade Web3 - Special EditionDMCC Future of Trade Web3 - Special Edition
DMCC Future of Trade Web3 - Special Edition
 
DSPy a system for AI to Write Prompts and Do Fine Tuning
DSPy a system for AI to Write Prompts and Do Fine TuningDSPy a system for AI to Write Prompts and Do Fine Tuning
DSPy a system for AI to Write Prompts and Do Fine Tuning
 
WordPress Websites for Engineers: Elevate Your Brand
WordPress Websites for Engineers: Elevate Your BrandWordPress Websites for Engineers: Elevate Your Brand
WordPress Websites for Engineers: Elevate Your Brand
 
Developer Data Modeling Mistakes: From Postgres to NoSQL
Developer Data Modeling Mistakes: From Postgres to NoSQLDeveloper Data Modeling Mistakes: From Postgres to NoSQL
Developer Data Modeling Mistakes: From Postgres to NoSQL
 
Gen AI in Business - Global Trends Report 2024.pdf
Gen AI in Business - Global Trends Report 2024.pdfGen AI in Business - Global Trends Report 2024.pdf
Gen AI in Business - Global Trends Report 2024.pdf
 
Passkey Providers and Enabling Portability: FIDO Paris Seminar.pptx
Passkey Providers and Enabling Portability: FIDO Paris Seminar.pptxPasskey Providers and Enabling Portability: FIDO Paris Seminar.pptx
Passkey Providers and Enabling Portability: FIDO Paris Seminar.pptx
 
New from BookNet Canada for 2024: Loan Stars - Tech Forum 2024
New from BookNet Canada for 2024: Loan Stars - Tech Forum 2024New from BookNet Canada for 2024: Loan Stars - Tech Forum 2024
New from BookNet Canada for 2024: Loan Stars - Tech Forum 2024
 
Unleash Your Potential - Namagunga Girls Coding Club
Unleash Your Potential - Namagunga Girls Coding ClubUnleash Your Potential - Namagunga Girls Coding Club
Unleash Your Potential - Namagunga Girls Coding Club
 
Streamlining Python Development: A Guide to a Modern Project Setup
Streamlining Python Development: A Guide to a Modern Project SetupStreamlining Python Development: A Guide to a Modern Project Setup
Streamlining Python Development: A Guide to a Modern Project Setup
 
Moving Beyond Passwords: FIDO Paris Seminar.pdf
Moving Beyond Passwords: FIDO Paris Seminar.pdfMoving Beyond Passwords: FIDO Paris Seminar.pdf
Moving Beyond Passwords: FIDO Paris Seminar.pdf
 

Memcached as a service using docker

  • 1. Install and Run Memcached as a service using docker on your server Install and Run Memcached as a service using docker Table of Contents Requirements................................................................................................................................................ 2 Installing Memcached on Docker ................................................................................................................. 3 Check for docker daemon ......................................................................................................................... 3 Installing Memcached ............................................................................................................................... 3 Commit your new container ..................................................................................................................... 4 Running and using Memcached on Docker .................................................................................................. 5 Running Memcached on Docker ............................................................................................................... 6 Using Memcached..................................................................................................................................... 6 Testing Memcached service...................................................................................................................... 8 Testing with Ruby.................................................................................................................................. 8 Testing with Python .............................................................................................................................. 8 Testing with PHP ................................................................................................................................... 9 Testing with Go ..................................................................................................................................... 9 http://www.slideshare.net/julienbarbier42/memcached-as-a-service-using-docker
  • 2. Install and Run Memcached as a service using docker on your server Requirements 1. Install last version of docker on your Operating System Please visit http://www.docker.io/gettingstarted/ to get docker installed on your Ubuntu or using Vagrant + VirtualBox on any other Operating system 2. Make sure you are running docker as a daemon. If it is not the case you can launch docker daemon by running sudo docker –d & http://www.slideshare.net/julienbarbier42/memcached-as-a-service-using-docker
  • 3. Install and Run Memcached as a service using docker on your server Installing Memcached on Docker Check for docker daemon Before starting, make sure docker is running as a daemon on your system. If it is not the case, please read the “Requirements” Section. ps aux | grep docker You should see a line with docker –d Installing Memcached docker run -d base apt-get -y install memcached This will give you the id of the new created container running your command apt-get. You will need to keep this id in order to use it later. In our example, the id is f1ab59fbc9d5 We can check that the installation is completed by using the docker logs command docker logs f1ab59fbc9d5 | less Remember to replace f1ab59fbc9d5 by your id before running this command. http://www.slideshare.net/julienbarbier42/memcached-as-a-service-using-docker
  • 4. Install and Run Memcached as a service using docker on your server Commit your new container We can commit our new container with the docker commit command, using our id. docker commit f1ab59fbc9d5 jbarbier/memcached Remember to replace f1ab59fbc9d5 by your id before running this command. You can also replace jbarbier/memcached with your own repository name. http://www.slideshare.net/julienbarbier42/memcached-as-a-service-using-docker
  • 5. Install and Run Memcached as a service using docker on your server This command gives you a new id which is the image id of your container. In our example it is c3b6fcb48266. Note that id so we can use it later. Let’s check that Memcached is installed on this image. To do so we can spawn a new container from this image and run bash inside. docker run -i -t jbarbier/memcached /bin/bash Remember to replace jbarbier/memcached by your repository name before running this command. We are now inside a container spawned from our image. Let’s see if Memcached is installed memcached OK! Note that you could have used the id of your image instead of the name of your repository. docker run -i -t c3b6fcb48266 /bin/bash Remember to replace c3b6fcb48266 by your image id before running this command. Running and using Memcached on Docker Now that we have an image with Memcached installed, let’s use it :) http://www.slideshare.net/julienbarbier42/memcached-as-a-service-using-docker
  • 6. Install and Run Memcached as a service using docker on your server Running Memcached on Docker docker run -d -p 11211 jbarbier/memcached memcached -u daemon Remember to replace jbarbier/memcached by your repository name before running this command. We need the –u option because Memcache can not run as root. In order to be able to use Memcached from outside our server, we canuse the –p 11211 option, which will ask docker to map the internal port of the container used by Memcached (11211), with a public port of the host. As usual, docker gives you back the id of the container you launched. In our case it is c360f228e22f. Note that id in order to use it later. Using Memcached In order to use Memcached from outside the localhost we need to know the host public port mapped by docker. In order to know that we can use the docker inspect command. docker inspect c360f228e22f Remember to replace c360f228e22f by your container id before running this command. This will give you a JSON output with plenty of configuration details. In the NetworkSettings/PortMapping you will find the public port you can use Memcached with from outside your server. http://www.slideshare.net/julienbarbier42/memcached-as-a-service-using-docker
  • 7. Install and Run Memcached as a service using docker on your server http://www.slideshare.net/julienbarbier42/memcached-as-a-service-using-docker
  • 8. Install and Run Memcached as a service using docker on your server In our case the public port is 49153. Testing Memcached service Let’s test and use our Memcached service, from an outside machine. In the following examples I will use 142.242.242.42 as the IP of the server where the container is running, and 49153 as the public port. Before running any of these examples be sure to replace the IP with your server IP, and the port number with the one docker inspect gave you. Testing with Ruby Guillotine:test_memcached jbarbier$ cat test.rb # run gem install dalli first require 'dalli' ip = '142.242.242.42' port = 49153 dc = Dalli::Client.new("#{ip}:#{port}") dc.set('abc', "Always Be Closing") value = dc.get('abc') puts value ruby test.rb Testing with Python Guillotine:test_memcached jbarbier$ cat test.py # pip install python-memcached if import memcache fails import memcache ip = '142.242.242.42' port = 49153 mc = memcache.Client(["{0}:{1}".format(ip, port)], debug=0) http://www.slideshare.net/julienbarbier42/memcached-as-a-service-using-docker
  • 9. Install and Run Memcached as a service using docker on your server mc.set("best_dev", "Guillaume C.") value = mc.get("best_dev") print value python test.py Testing with PHP Guillotine:test_memcached jbarbier$ cat test.php <?php $ip = '142.242.242.42'; $port = 49153; $memcache_obj = new Memcache; $memcache_obj->connect($ip, $port); $memcache_obj->set('rule_1', 'You DO NOT talk about FIGHT CLUB'); $v = $memcache_obj->get('rule_1'); echo "$vn"; ?> php test.php Testing with Go Guillotine:test_memcached jbarbier$ cat test.go package main import ( "fmt" "github.com/kklis/gomemcache" ) http://www.slideshare.net/julienbarbier42/memcached-as-a-service-using-docker
  • 10. Install and Run Memcached as a service using docker on your server func main() { ip := "142.242.242.42" port := 49153 memc, err := gomemcache.Connect(ip, port) if err != nil { panic(err) } err = memc.Set("foo", []byte("bar"), 0, 0) if err != nil { panic(err) } val, _, _ := memc.Get("foo") fmt.Printf("%sn", val) } Go run test.go http://www.slideshare.net/julienbarbier42/memcached-as-a-service-using-docker