运行dockerfile时,rabbitmq设置不会保留

时间:2014-10-17 19:05:40

标签: rabbitmq docker

我有任何我想要的申请:

  1. 运行rabbitmq-server
  2. 设置一些队列和交换(我有一个setuprabbit.py脚本)
  3. 然后运行一些脚本(在主管中完成)......但在此之前我必须设置兔子
  4. 我的Dockerfile看起来像这样:

    RUN cd /var && wget -q http://www.rabbitmq.com/releases/rabbitmq-server/v2.8.2/rabbitmq-server-generic-unix-2.8.2.tar.gz
    
    RUN cd /var && tar -xzvf rabbitmq-server-generic-unix-2.8.2.tar.gz && rm rabbitmq-server-generic-unix-2.8.2.tar.gz
    ENV PATH /var/rabbitmq_server-2.8.2/sbin/:$PATH
    
    RUN rabbitmq-plugins enable rabbitmq_management && rabbitmq-server -detached && sleep 5 &&  cd /tmp/ && rabbitmqctl start_app && python buzz/scripts/setuprabbit.py
    #RUN rabbitmq-server -detached && sleep 5 &&  cd /tmp/ && rabbitmqctl start_app && python buzz/scripts/setuprabbit.py
    
    CMD ["supervisord", "-c", "/etc/supervisor/supervisord.conf"]
    

    当我进行构建时,它在这里失败了(sudo docker build .)......它通过但我可以看到,当主管运行脚本时... rabbitmq不再运行(兔子节点已关闭)。

    如何坚持兔子设置e.t.c?

    这是我的完整Dockerfile

    FROM ubuntu:precise
    MAINTAINER njain
    #VOLUME ["home/njain/office/buzz"]
    ADD .  /tmp/
    # DOCKER-VERSION 0.3.4
    # Docker basics
    RUN apt-get -y update
    
    # EDITORS
    #RUN apt-get install -y -q vim
    
    ## PYTHON
    RUN apt-get install -y -q python-software-properties
    RUN apt-get install -y -q python
    RUN apt-get install -y -q python-setuptools
    RUN apt-get install -y -q python-virtualenv
    RUN apt-get install -y -q python-dev
    RUN apt-get install -y -q python-distribute
    #RUN apt-get install -y -q build-essential
    RUN apt-get install -y -q python-pip
    RUN pip --no-input  install --upgrade pip
    
    # LIBS
    RUN apt-get install -y -q libjpeg8-dev
    RUN apt-get install -y -q zlib1g-dev
    RUN apt-get install -y -q libfreetype6-dev
    RUN apt-get install -y -q liblcms1-dev
    RUN apt-get install -y -q libwebp-dev
    RUN apt-get install -y -q libtiff-dev
    RUN apt-get install -y -q libffi-dev
    # TOOLS
    RUN apt-get install -y -q curl
    RUN apt-get install -y -q git
    RUN apt-get install -y -q vim
    
    #RABBIT
    RUN apt-get install -y -q rabbitmq-server
    #RUN /usr/sbin/rabbitmq-plugins enable rabbitmq_management
    
    # Install supervisor
    RUN apt-get install -y supervisor
    RUN mkdir -p /var/run/sshd
    RUN mkdir -p /var/log/supervisor
    RUN mkdir -p /etc/supervisor/conf.d
    RUN mkdir -p /var/run/sshd /var/log/supervisor
    COPY supervisord.conf /etc/supervisor/supervisord.conf
    
    RUN pip --no-input install virtualenv
    
    
    #RUN cd /tmp/
    RUN  cd /tmp/ && virtualenv buzzenv &&   python setup.py install
    
    #RUN  rabbitmq-server start &
    #RUN  python /tmp/buzz/scripts/setuprabbit.py
    
    # Install RabbitMQ.
    RUN apt-get update
    RUN apt-get -f install
    RUN apt-get install wget
    #RUN \
    #wget -qO - http://www.rabbitmq.com/rabbitmq-signing-key-public.asc | apt-key add - && \
    #echo "deb http://www.rabbitmq.com/debian/ testing main" > /etc/apt/sources.list.d/rabbitmq.list && \
    #apt-get update && \
    #DEBIAN_FRONTEND=noninteractive apt-get install -y rabbitmq-server && \
    #rm -rf /var/lib/apt/lists/* && \
    #rabbitmq-plugins enable rabbitmq_management && \
    #echo "[{rabbit, [{loopback_users, []}]}]." > /etc/rabbitmq/rabbitmq.config
    
    # Define RabbitMQ variables.
    #RUN mkdir -p /data/mnesia
    #RUN chown -R rabbitmq:rabbitmq /data
    #ENV RABBITMQ_LOG_BASE /var/log/rabbitmq
    #ENV RABBITMQ_MNESIA_BASE /data/mnesia
    #EXPOSE 5672
    #EXPOSE 15672
    #RUN echo "NODENAME=rabbit@localhost" > /var/rabbitmq-env.conf
    
    
    RUN cd /var && wget -q http://www.rabbitmq.com/releases/rabbitmq-server/v2.8.2/rabbitmq-server-generic-unix-2.8.2.tar.gz
    
    RUN cd /var && tar -xzvf rabbitmq-server-generic-unix-2.8.2.tar.gz && rm rabbitmq-server-generic-unix-2.8.2.tar.gz
    ENV PATH /var/rabbitmq_server-2.8.2/sbin/:$PATH
    
    RUN rabbitmq-plugins enable rabbitmq_management && rabbitmq-server -detached && sleep 5 &&  cd /tmp/ && rabbitmqctl start_app && python buzz/scripts/setuprabbit.py
    #RUN rabbitmq-server -detached && sleep 5 &&  cd /tmp/ && rabbitmqctl start_app && python buzz/scripts/setuprabbit.py
    
    CMD ["supervisord", "-c", "/etc/supervisor/supervisord.conf"]
    

1 个答案:

答案 0 :(得分:2)

由于docker的工作方式......运行后

RUN rabbitmq-plugins enable rabbitmq_management && \
    rabbitmq-server -detached && \
    sleep 5 && \
    cd /tmp/ && \
    rabbitmqctl start_app && \
    python buzz/scripts/setuprabbit.py

它停止了兔子服务器。

为了确保保存状态,我需要

RUN rabbitmq-plugins enable rabbitmq_management && \
    rabbitmq-server -detached && \
    sleep 5 && \
    cd /tmp/ && \
    rabbitmqctl start_app && \
    python buzz/scripts/setuprabbit.py && \
    rabbitmqctl stop_app

然后在下一步再次启动rabbitmq-server