您的位置:首页 > 运维架构 > Docker

Docker使用supervisor构建memcached

2014-11-27 15:37 381 查看
1.使用Dockerfile文件直接构建

Dockerfile

FROM centos:centos6
MAINTAINER  aaron "aaron.docker@gmail.com"

#Install supervisor
RUN rpm -ivh http://dl.fedoraproject.org/pub/epel/6/x86_64/epel-release-6-8.noarch.rpm RUN yum -y update  && yum -y install python-pip && /usr/bin/pip install supervisor
RUN mkdir -p /etc/supervisor/conf.d && mkdir -p /var/log/supervisor
COPY supervisord.conf /etc/supervisord.conf
VOLUME /var/log/supervisor

#install sshd
RUN yum install -y openssh-server && sed -i 's/UsePAM yes/UsePAM no/g' /etc/ssh/sshd_config
# select root pasword
RUN echo "root:pasword" | chpasswd && echo "root   ALL=(ALL)       ALL" >> /etc/sudoers
RUN ssh-keygen -t dsa -f /etc/ssh/ssh_host_dsa_key && ssh-keygen -t rsa -f /etc/ssh/ssh_host_rsa_key
RUN mkdir /var/run/sshd

#Install libevent
RUN yum -y install wget && yum -y install tar && yum -y install gcc && yum -y install perl-Test-Harness
RUN wget https://github.com/downloads/libevent/libevent/libevent-2.0.21-stable.tar.gz &&\
tar xzf libevent-2.0.21-stable.tar.gz &&\
cd libevent-2.0.21-stable &&\
./configure --prefix=/usr &&\
make && make install
#Install memcached
RUN wget http://memcached.org/latest && mv latest memcached-1.4.21.tar.gz && \
tar xzf memcached-1.4.21.tar.gz &&\
cd memcached-1.4.21 &&\
./configure --prefix=/usr/local/memcache --with-libevent=/usr &&\
make && make install

EXPOSE 22 11211
CMD ["/usr/bin/supervisord"]


构建

新建build.conf、build.sh

build.conf

DOCKER_USER=aarongo
DOCKER_IMAGE_NAME=centos-memcache-supervisor
DOCKER_IMAGE_TAG=latest
DOCKER_IMAGE_REPOSITORY_NAME=${DOCKER_USER}/${DOCKER_IMAGE_NAME}:${DOCKER_IMAGE_TAG}


build.sh

#!/usr/bin/env bash

# Change working directory
DIR_PATH="$( cd "$( echo "${0%/*}" )"; pwd )"
if [[ $DIR_PATH == */* ]]; then
cd $DIR_PATH
fi

NO_CACHE="$1"

source build.conf

show_docker_image ()
{
NAME=$1
NAME_PARTS=(${NAME//:/ })

# Set 'latest' tag if no tag requested
if [ ${#NAME_PART[@]} == 1 ]; then
NAME_PARTS[1]='latest'
fi

docker images | grep -e "^${NAME_PARTS[0]}[ ]\{1,\}${NAME_PARTS[1]}"
}

echo Building ${DOCKER_IMAGE_REPOSITORY_NAME}...

# Allow cache to be bypassed
if [ "$NO_CACHE" == "true" ]; then
echo " ---> Skipping cache"
else
NO_CACHE="false"
fi

# Build from working directory
docker build --no-cache=$NO_CACHE -t ${DOCKER_IMAGE_REPOSITORY_NAME} .

# Display the last docker image
echo "Docker image:"
show_docker_image ${DOCKER_IMAGE_REPOSITORY_NAME}

echo " ---> Build complete"


配置好buid.conf后直接运行build.sh 可直接完成
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: