在docker容器中使用mongodb和redis

日期 2016-04-15
在docker容器中使用mongodb和redis

在一个Dockerfile 中同时配置mongodb,redis和ssh
直接上代码

Dockerfile 文件

FROM ubuntu:14.04
MAINTAINER ZHENGLI <[email protected]>

ENV DEBIAN_FRONTEND noninteractive

RUN dpkg-divert --local --rename --add /etc/init.d/mongod
RUN ln -s /bin/true /etc/init.d/mongod

RUN apt-key adv --keyserver hkp://keyserver.ubuntu.com:80 --recv EA312927

RUN echo "deb http://repo.mongodb.org/apt/ubuntu trusty/mongodb-org/3.2 multiverse" | tee /etc/apt/sources.list.d/mongodb-org-3.2.list

#Install packages
RUN apt-get update
RUN apt-get install -y openssh-server supervisor redis-server mongodb-org

# Create the MongoDB data directory
RUN mkdir -p /data/db
RUN mkdir /var/run/supervisor



#SSH
RUN mkdir /var/run/sshd
#修改密码
RUN echo 'root:admin' | chpasswd

RUN mkdir -p /var/run/sshd && sed -i "s/PermitRootLogin.*/PermitRootLogin yes/g" /etc/ssh/sshd_config

# SSH login fix. Otherwise user is kicked off after login
RUN sed '[email protected]\s*required\s*[email protected] optional [email protected]' -i /etc/pam.d/sshd

ENV NOTVISIBLE "in users profile"
RUN echo "export VISIBLE=now" >> /etc/profile

EXPOSE 22
EXPOSE 80


EXPOSE 6379
EXPOSE 27017

COPY supervisord.conf /etc/supervisor/conf.d/supervisord.conf

CMD ["/usr/bin/supervisord"]

ssh root密码admin,请自行修改

supervisord.conf 文件:

[supervisord]
nodaemon=true


[program:sshd]
command=/usr/sbin/sshd -D

[program:mongodb]
command=/usr/bin/mongod
user=mongodb

[program:redis]
command=/usr/bin/redis-server

以上配置即可在容器启动后自动运行mongodb和redis,如果要指定mongodb或redis的启动配置文件,修改supervisord.conf 文件中的command 即可。