SlideShare ist ein Scribd-Unternehmen logo
1 von 10
Downloaden Sie, um offline zu lesen
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

Weitere ähnliche Inhalte

Andere mochten auch

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
 

Andere mochten auch (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入門: コンテナ型仮想化技術の仕組みと使い方
 

Mehr von 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
 

Mehr von 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...
 

Kürzlich hochgeladen

Driving Behavioral Change for Information Management through Data-Driven Gree...
Driving Behavioral Change for Information Management through Data-Driven Gree...Driving Behavioral Change for Information Management through Data-Driven Gree...
Driving Behavioral Change for Information Management through Data-Driven Gree...Enterprise Knowledge
 
A Call to Action for Generative AI in 2024
A Call to Action for Generative AI in 2024A Call to Action for Generative AI in 2024
A Call to Action for Generative AI in 2024Results
 
08448380779 Call Girls In Greater Kailash - I Women Seeking Men
08448380779 Call Girls In Greater Kailash - I Women Seeking Men08448380779 Call Girls In Greater Kailash - I Women Seeking Men
08448380779 Call Girls In Greater Kailash - I Women Seeking MenDelhi Call girls
 
04-2024-HHUG-Sales-and-Marketing-Alignment.pptx
04-2024-HHUG-Sales-and-Marketing-Alignment.pptx04-2024-HHUG-Sales-and-Marketing-Alignment.pptx
04-2024-HHUG-Sales-and-Marketing-Alignment.pptxHampshireHUG
 
[2024]Digital Global Overview Report 2024 Meltwater.pdf
[2024]Digital Global Overview Report 2024 Meltwater.pdf[2024]Digital Global Overview Report 2024 Meltwater.pdf
[2024]Digital Global Overview Report 2024 Meltwater.pdfhans926745
 
Automating Google Workspace (GWS) & more with Apps Script
Automating Google Workspace (GWS) & more with Apps ScriptAutomating Google Workspace (GWS) & more with Apps Script
Automating Google Workspace (GWS) & more with Apps Scriptwesley chun
 
Boost PC performance: How more available memory can improve productivity
Boost PC performance: How more available memory can improve productivityBoost PC performance: How more available memory can improve productivity
Boost PC performance: How more available memory can improve productivityPrincipled Technologies
 
Understanding Discord NSFW Servers A Guide for Responsible Users.pdf
Understanding Discord NSFW Servers A Guide for Responsible Users.pdfUnderstanding Discord NSFW Servers A Guide for Responsible Users.pdf
Understanding Discord NSFW Servers A Guide for Responsible Users.pdfUK Journal
 
Strategies for Unlocking Knowledge Management in Microsoft 365 in the Copilot...
Strategies for Unlocking Knowledge Management in Microsoft 365 in the Copilot...Strategies for Unlocking Knowledge Management in Microsoft 365 in the Copilot...
Strategies for Unlocking Knowledge Management in Microsoft 365 in the Copilot...Drew Madelung
 
Handwritten Text Recognition for manuscripts and early printed texts
Handwritten Text Recognition for manuscripts and early printed textsHandwritten Text Recognition for manuscripts and early printed texts
Handwritten Text Recognition for manuscripts and early printed textsMaria Levchenko
 
GenCyber Cyber Security Day Presentation
GenCyber Cyber Security Day PresentationGenCyber Cyber Security Day Presentation
GenCyber Cyber Security Day PresentationMichael W. Hawkins
 
IAC 2024 - IA Fast Track to Search Focused AI Solutions
IAC 2024 - IA Fast Track to Search Focused AI SolutionsIAC 2024 - IA Fast Track to Search Focused AI Solutions
IAC 2024 - IA Fast Track to Search Focused AI SolutionsEnterprise Knowledge
 
CNv6 Instructor Chapter 6 Quality of Service
CNv6 Instructor Chapter 6 Quality of ServiceCNv6 Instructor Chapter 6 Quality of Service
CNv6 Instructor Chapter 6 Quality of Servicegiselly40
 
The 7 Things I Know About Cyber Security After 25 Years | April 2024
The 7 Things I Know About Cyber Security After 25 Years | April 2024The 7 Things I Know About Cyber Security After 25 Years | April 2024
The 7 Things I Know About Cyber Security After 25 Years | April 2024Rafal Los
 
Artificial Intelligence: Facts and Myths
Artificial Intelligence: Facts and MythsArtificial Intelligence: Facts and Myths
Artificial Intelligence: Facts and MythsJoaquim Jorge
 
Breaking the Kubernetes Kill Chain: Host Path Mount
Breaking the Kubernetes Kill Chain: Host Path MountBreaking the Kubernetes Kill Chain: Host Path Mount
Breaking the Kubernetes Kill Chain: Host Path MountPuma Security, LLC
 
Data Cloud, More than a CDP by Matt Robison
Data Cloud, More than a CDP by Matt RobisonData Cloud, More than a CDP by Matt Robison
Data Cloud, More than a CDP by Matt RobisonAnna Loughnan Colquhoun
 
A Domino Admins Adventures (Engage 2024)
A Domino Admins Adventures (Engage 2024)A Domino Admins Adventures (Engage 2024)
A Domino Admins Adventures (Engage 2024)Gabriella Davis
 
Real Time Object Detection Using Open CV
Real Time Object Detection Using Open CVReal Time Object Detection Using Open CV
Real Time Object Detection Using Open CVKhem
 
Scaling API-first – The story of a global engineering organization
Scaling API-first – The story of a global engineering organizationScaling API-first – The story of a global engineering organization
Scaling API-first – The story of a global engineering organizationRadu Cotescu
 

Kürzlich hochgeladen (20)

Driving Behavioral Change for Information Management through Data-Driven Gree...
Driving Behavioral Change for Information Management through Data-Driven Gree...Driving Behavioral Change for Information Management through Data-Driven Gree...
Driving Behavioral Change for Information Management through Data-Driven Gree...
 
A Call to Action for Generative AI in 2024
A Call to Action for Generative AI in 2024A Call to Action for Generative AI in 2024
A Call to Action for Generative AI in 2024
 
08448380779 Call Girls In Greater Kailash - I Women Seeking Men
08448380779 Call Girls In Greater Kailash - I Women Seeking Men08448380779 Call Girls In Greater Kailash - I Women Seeking Men
08448380779 Call Girls In Greater Kailash - I Women Seeking Men
 
04-2024-HHUG-Sales-and-Marketing-Alignment.pptx
04-2024-HHUG-Sales-and-Marketing-Alignment.pptx04-2024-HHUG-Sales-and-Marketing-Alignment.pptx
04-2024-HHUG-Sales-and-Marketing-Alignment.pptx
 
[2024]Digital Global Overview Report 2024 Meltwater.pdf
[2024]Digital Global Overview Report 2024 Meltwater.pdf[2024]Digital Global Overview Report 2024 Meltwater.pdf
[2024]Digital Global Overview Report 2024 Meltwater.pdf
 
Automating Google Workspace (GWS) & more with Apps Script
Automating Google Workspace (GWS) & more with Apps ScriptAutomating Google Workspace (GWS) & more with Apps Script
Automating Google Workspace (GWS) & more with Apps Script
 
Boost PC performance: How more available memory can improve productivity
Boost PC performance: How more available memory can improve productivityBoost PC performance: How more available memory can improve productivity
Boost PC performance: How more available memory can improve productivity
 
Understanding Discord NSFW Servers A Guide for Responsible Users.pdf
Understanding Discord NSFW Servers A Guide for Responsible Users.pdfUnderstanding Discord NSFW Servers A Guide for Responsible Users.pdf
Understanding Discord NSFW Servers A Guide for Responsible Users.pdf
 
Strategies for Unlocking Knowledge Management in Microsoft 365 in the Copilot...
Strategies for Unlocking Knowledge Management in Microsoft 365 in the Copilot...Strategies for Unlocking Knowledge Management in Microsoft 365 in the Copilot...
Strategies for Unlocking Knowledge Management in Microsoft 365 in the Copilot...
 
Handwritten Text Recognition for manuscripts and early printed texts
Handwritten Text Recognition for manuscripts and early printed textsHandwritten Text Recognition for manuscripts and early printed texts
Handwritten Text Recognition for manuscripts and early printed texts
 
GenCyber Cyber Security Day Presentation
GenCyber Cyber Security Day PresentationGenCyber Cyber Security Day Presentation
GenCyber Cyber Security Day Presentation
 
IAC 2024 - IA Fast Track to Search Focused AI Solutions
IAC 2024 - IA Fast Track to Search Focused AI SolutionsIAC 2024 - IA Fast Track to Search Focused AI Solutions
IAC 2024 - IA Fast Track to Search Focused AI Solutions
 
CNv6 Instructor Chapter 6 Quality of Service
CNv6 Instructor Chapter 6 Quality of ServiceCNv6 Instructor Chapter 6 Quality of Service
CNv6 Instructor Chapter 6 Quality of Service
 
The 7 Things I Know About Cyber Security After 25 Years | April 2024
The 7 Things I Know About Cyber Security After 25 Years | April 2024The 7 Things I Know About Cyber Security After 25 Years | April 2024
The 7 Things I Know About Cyber Security After 25 Years | April 2024
 
Artificial Intelligence: Facts and Myths
Artificial Intelligence: Facts and MythsArtificial Intelligence: Facts and Myths
Artificial Intelligence: Facts and Myths
 
Breaking the Kubernetes Kill Chain: Host Path Mount
Breaking the Kubernetes Kill Chain: Host Path MountBreaking the Kubernetes Kill Chain: Host Path Mount
Breaking the Kubernetes Kill Chain: Host Path Mount
 
Data Cloud, More than a CDP by Matt Robison
Data Cloud, More than a CDP by Matt RobisonData Cloud, More than a CDP by Matt Robison
Data Cloud, More than a CDP by Matt Robison
 
A Domino Admins Adventures (Engage 2024)
A Domino Admins Adventures (Engage 2024)A Domino Admins Adventures (Engage 2024)
A Domino Admins Adventures (Engage 2024)
 
Real Time Object Detection Using Open CV
Real Time Object Detection Using Open CVReal Time Object Detection Using Open CV
Real Time Object Detection Using Open CV
 
Scaling API-first – The story of a global engineering organization
Scaling API-first – The story of a global engineering organizationScaling API-first – The story of a global engineering organization
Scaling API-first – The story of a global engineering organization
 

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