Vikri Usman Rizky
Vikri Usman Rizky

Reputation: 47

Is there a way to set the run level on the docker?

i want to create ubuntu based container and install rabbitmq inside it

i tried docker run -dit ubuntu:18.04 and install rabbitmq manually inside the container to get the list step for my dockerfile. when i build my dockerfile into docker image, it fail. and show

Not creating home directory `/var/lib/rabbitmq'.
invoke-rc.d: could not determine current runlevel
invoke-rc.d: policy-rc.d denied execution of start.
Processing triggers for libc-bin (2.27-3ubuntu1) ...

and

Error: unable to connect to node rabbit@2e1645badb1d: nodedown

DIAGNOSTICS
===========

attempted to contact: [rabbit@2e1645badb1d]

rabbit@2e1645badb1d:
  * connected to epmd (port 4369) on 2e1645badb1d
  * epmd reports: node 'rabbit' not running at all
                  no other nodes on 2e1645badb1d
  * suggestion: start the node

current node details:
- node name: 'rabbitmq-cli-01@2e1645badb1d'
- home dir: /var/lib/rabbitmq
- cookie hash: WYOXjiEogBIOb2jBVZzkPw==

and this is my dockerfile

FROM ubuntu:18.04


RUN apt-get update
RUN apt-get install rabbitmq-server -y
RUN service rabbitmq-server start
RUN rabbitmq-plugins enable rabbitmq_management
RUN rabbitmqctl start_app
RUN rabbitmqctl add_user test1 test1
RUN rabbitmqctl set_user_tags test1 administrator
RUN rabbitmqctl set_permissions -p / test1 ".*" ".*" ".*"

EXPOSE 25672
EXPOSE 5672
EXPOSE 15672
EXPOSE 4369

it should run normally, because the steps I put into the dockerfile are the same.

is there someone here who can show me what to do

Upvotes: 1

Views: 2389

Answers (1)

ckaserer
ckaserer

Reputation: 5702

In short: No. Those commands do not work exactly the same in your running container as in build.

Each of your commands that you execute creates a container. The docker build command (e.g. RUN) will then be executed in that container and then saved as an image.

IMPORTANT running processes terminate when the image is saved. Background/daemon processes do not work with docker - that is by design ;) That means avoid if possible to run commands like "service start" in your dockerfile (since that will not persist to the next layer / command.

I recommend that you use the official image provided by rabbitMQ https://hub.docker.com/_/rabbitmq

You can inspect the associated Dockerfile for latest here: https://github.com/docker-library/rabbitmq/blob/b8ca2ef2814cf35de476e763db94eb9706657f3c/3.8/ubuntu/Dockerfile

If you still would like to go with your Dockerfile it needs to look something like this (to keep the process running)

FROM ubuntu:18.04

RUN apt-get update
RUN apt-get install rabbitmq-server -y
RUN service rabbitmq-server start && \
    rabbitmq-plugins enable rabbitmq_management && \
    rabbitmqctl start_app && \
    rabbitmqctl add_user test1 test1 && \
    rabbitmqctl set_user_tags test1 administrator && \
    rabbitmqctl set_permissions -p / test1 ".*" ".*" ".*" && \
    service rabbitmq-server stop

EXPOSE 4369 5671 5672 25672
CMD ["rabbitmq-server"]

Upvotes: 2

Related Questions