链接到泊坞窗memcached的容器 [英] Linking to a Docker memcached container

查看:150
本文介绍了链接到泊坞窗memcached的容器的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我一直在尝试用多克尔了几天,并已发展到喜欢它。不过,还是有很多躲避我的几件事情。以下是我迄今

I have been experimenting with Docker for a few days now and have grown to like it. However, there are a few things that still elude me. Here is what I have thus far

创建小尺寸的Ubuntu 14.04图片

//I got this from a post on this forum 
#!/bin/bash

docker rm ubuntu-essential-multilayer 2>/dev/null
set -ve
docker build -t textlab/ubuntu-essential-multilayer - <<'EOF'
FROM ubuntu:14.04
# Make an exception for apt: it gets deselected, even though it probably shouldn't.
RUN dpkg --clear-selections && echo apt install |dpkg --set-selections && \
SUDO_FORCE_REMOVE=yes DEBIAN_FRONTEND=noninteractive apt-get --purge -y dselect-upgrade && \
dpkg-query -Wf '${db:Status-Abbrev}\t${binary:Package}\n' |grep '^.i' |awk -F'\t' '{print $2 " install"}' |dpkg --set-selections && \
rm -r /var/cache/apt /var/lib/apt/lists
EOF
TMP_FILE="`mktemp -t ubuntu-essential-XXXXXXX.tar.gz`"
docker run --rm -i textlab/ubuntu-essential-multilayer tar zpc --exclude=/etc/hostname \
--exclude=/etc/resolv.conf --exclude=/etc/hosts --one-file-system / >"$TMP_FILE"
docker rmi textlab/ubuntu-essential-multilayer
docker import - textlab/ubuntu-essential-nocmd <"$TMP_FILE"
docker build -t textlab/ubuntu-essential - <<'EOF'
FROM textlab/ubuntu-essential-nocmd
CMD ["/bin/bash"]
EOF
docker rmi textlab/ubuntu-essential-nocmd
rm -f "$TMP_FILE"

对于Apache图像创建Dockerfile

FROM textlab/ubuntu-essential


RUN apt-get update && apt-get -y install apache2 && apt-get clean
RUN a2enmod ssl

ENV APACHE_RUN_USER www-data
ENV APACHE_RUN_GROUP www-data
ENV APACHE_LOG_DIR /var/log/apache2

EXPOSE 80
EXPOSE 443

CMD ["/usr/sbin/apache2ctl", "-D", "FOREGROUND"]

docker build -t droidos/apache .

创建Dockerfile为PHP5

FROM droidos/apache

RUN apt-get update && apt-get -y --reinstall install php5 php5-redis php5-memcached php5-curl libssh2-php php5-mysqlnd php5-mcrypt && apt-get clean
RUN php5enmod mcrypt

ENV APACHE_RUN_USER www-data
ENV APACHE_RUN_GROUP www-data
ENV APACHE_LOG_DIR /var/log/apache2

EXPOSE 80
EXPOSE 443

CMD ["/usr/sbin/apache2ctl", "-D", "FOREGROUND"]

docker build -t droidos/php5 .

创建的memcached一个Dockerfile和构建图片

FROM textlab/ubuntu-essential
# Install packages
RUN DEBIAN_FRONTEND=noninteractive apt-get update
RUN DEBIAN_FRONTEND=noninteractive apt-get -y install memcached

# memcached public variable 

EXPOSE 11211

CMD ["/usr/bin/memcached", "-u", "memcache", "-v"]

docker build -t droidos/memcached .

Fireup与memcached的码头工人,容器

docker run -d -P --name memcached droidos/memcached

Fireup泊坞窗容器与Apache并将其链接到创建的memcached的容器较早

docker run -d --name apache --link memcached:memcached -v /var/droidos/site:/var/www/html -v /var/droidos/logs:/var/log/apache2 -p 8080:80 droidos/php5 

浏览example.com:8080

似乎一切都OK

创建在/ var / droidos /网站memcached的测试脚本

<?php
error_reporting(E_ALL); 
header('Content-type:text/plain');
$mc = new Memcached(); 
$mc->addServer("localhost", 11211); 

$flag = $mc->add('name','droidos'); 
echo ($flag)?'y':'n';
echo $mc->getResultCode();
?>

该脚本返回 N47 这意味着memcached服务器是禁用的。

This script returns n47 implying that the memcached server is disabled.

无论我的链接是不正确或memcached的尚未启动或memcached的集装箱港口是不是在apache的容器中可见。 ssh方式连接到memcached的容器

Either my linking is incorrect or memcached has not been started or the memcached container port is not visible in the apache container. SSHing into the memcached container

docker exec -it <container-id> /bin/bash 

和运行

service memcached status

表示该服务其实也不是跑步。所以我启动它

indicates that the service is not in fact running. So I start it

service memcached start

验证已启动及以上再次运行该脚本。没有快乐 - 我仍然得到一个答复N47,而不是我想看到的Y0。很显然,我在这里的某个地方缺少一个步骤。我会不胜感激的人谁也许能告诉我什么,可能是。

verify it has started and run the script above again. No joy - I still get an n47 reply rather than the y0 I would like to see. Clearly, I am missing a step somewhere here. I'd be most obliged to anyone who might be able to tell me what that might be.

推荐答案

我想是因为你想从Apache容器连接到Apache容器的本地主机访问memcached的,而memcached的容器是由访问失败Apache的一个在一个不同的IP地址。

I think it fails because you're trying to access memcached from the apache container connecting to the localhost of the apache container, while the memcached container is made accessible to the apache one on a different IP address.

这是我认为该行是错误的:

This is the line I think is wrong:

$mc->addServer("localhost", 11211);

当你链接集装箱,码头工人增加了对源容器主机条目到 / etc / hosts中文件(见的有关链接文档)。

When you link containers, Docker adds a host entry for the source container to the /etc/hosts file (see the docs about linking).

因此​​,你应该能够从Apache容器连接到使用此命令PHP memcached的一项:

Therefore you should be able to connect from the apache container to the memcached one using this PHP command:

$mc->addServer("memcached", 11211);

如果它不工作,请检查您可以从memcached的容器本身连接到memcached的服务。

If it doesn't work, check that you can connect to the memcached service from the memcached container itself.

这篇关于链接到泊坞窗memcached的容器的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆