How to add initial users when starting a RabbitMQ Docker container?
Currently i am starting RabbitMQ Docker container using the default RabbitMQ image from DockerHub. Using the following commands.
docker run --restart=always
-d
-e RABBITMQ_NODENAME=rabbitmq
-v /opt/docker/rabbitmq/data:/var/lib/rabbitmq/mnesia/rabbitmq
-p 5672:5672
-p 15672:15672
--name rabbitmq rabbitmq:3-management
I have a need where i want to provide defaults users / and virtual-hosts when the image is first started. For example to create a default 'test-user'.
Currently i have to do that manually by using the management plugin and adding the users / virtual-hosts via the web ui. Is there a way i can provide default settings when starting the RabbitMQ image?
docker rabbitmq
add a comment |
Currently i am starting RabbitMQ Docker container using the default RabbitMQ image from DockerHub. Using the following commands.
docker run --restart=always
-d
-e RABBITMQ_NODENAME=rabbitmq
-v /opt/docker/rabbitmq/data:/var/lib/rabbitmq/mnesia/rabbitmq
-p 5672:5672
-p 15672:15672
--name rabbitmq rabbitmq:3-management
I have a need where i want to provide defaults users / and virtual-hosts when the image is first started. For example to create a default 'test-user'.
Currently i have to do that manually by using the management plugin and adding the users / virtual-hosts via the web ui. Is there a way i can provide default settings when starting the RabbitMQ image?
docker rabbitmq
1
In respect to the answer i got wrote a small blogpost writing down the process and files involved. mpas.github.io/post/2015/06/docker-rabbitmq-default-users
– Marco
Jun 11 '15 at 11:44
1
Blog post link update mpas.github.io/2015/06/11/…
– Janusz Skonieczny
Oct 28 '16 at 14:13
add a comment |
Currently i am starting RabbitMQ Docker container using the default RabbitMQ image from DockerHub. Using the following commands.
docker run --restart=always
-d
-e RABBITMQ_NODENAME=rabbitmq
-v /opt/docker/rabbitmq/data:/var/lib/rabbitmq/mnesia/rabbitmq
-p 5672:5672
-p 15672:15672
--name rabbitmq rabbitmq:3-management
I have a need where i want to provide defaults users / and virtual-hosts when the image is first started. For example to create a default 'test-user'.
Currently i have to do that manually by using the management plugin and adding the users / virtual-hosts via the web ui. Is there a way i can provide default settings when starting the RabbitMQ image?
docker rabbitmq
Currently i am starting RabbitMQ Docker container using the default RabbitMQ image from DockerHub. Using the following commands.
docker run --restart=always
-d
-e RABBITMQ_NODENAME=rabbitmq
-v /opt/docker/rabbitmq/data:/var/lib/rabbitmq/mnesia/rabbitmq
-p 5672:5672
-p 15672:15672
--name rabbitmq rabbitmq:3-management
I have a need where i want to provide defaults users / and virtual-hosts when the image is first started. For example to create a default 'test-user'.
Currently i have to do that manually by using the management plugin and adding the users / virtual-hosts via the web ui. Is there a way i can provide default settings when starting the RabbitMQ image?
docker rabbitmq
docker rabbitmq
asked Jun 10 '15 at 5:03
MarcoMarco
5,4202277149
5,4202277149
1
In respect to the answer i got wrote a small blogpost writing down the process and files involved. mpas.github.io/post/2015/06/docker-rabbitmq-default-users
– Marco
Jun 11 '15 at 11:44
1
Blog post link update mpas.github.io/2015/06/11/…
– Janusz Skonieczny
Oct 28 '16 at 14:13
add a comment |
1
In respect to the answer i got wrote a small blogpost writing down the process and files involved. mpas.github.io/post/2015/06/docker-rabbitmq-default-users
– Marco
Jun 11 '15 at 11:44
1
Blog post link update mpas.github.io/2015/06/11/…
– Janusz Skonieczny
Oct 28 '16 at 14:13
1
1
In respect to the answer i got wrote a small blogpost writing down the process and files involved. mpas.github.io/post/2015/06/docker-rabbitmq-default-users
– Marco
Jun 11 '15 at 11:44
In respect to the answer i got wrote a small blogpost writing down the process and files involved. mpas.github.io/post/2015/06/docker-rabbitmq-default-users
– Marco
Jun 11 '15 at 11:44
1
1
Blog post link update mpas.github.io/2015/06/11/…
– Janusz Skonieczny
Oct 28 '16 at 14:13
Blog post link update mpas.github.io/2015/06/11/…
– Janusz Skonieczny
Oct 28 '16 at 14:13
add a comment |
8 Answers
8
active
oldest
votes
You can create a simple Dockerfile that extends the functionality of the basic image and creates a default user.
The Docker file you need is the following:
FROM rabbitmq
# Define environment variables.
ENV RABBITMQ_USER user
ENV RABBITMQ_PASSWORD user
ADD init.sh /init.sh
EXPOSE 15672
# Define default command
CMD ["/init.sh"]
And the init.sh:
#!/bin/sh
# Create Rabbitmq user
( sleep 5 ;
rabbitmqctl add_user $RABBITMQ_USER $RABBITMQ_PASSWORD 2>/dev/null ;
rabbitmqctl set_user_tags $RABBITMQ_USER administrator ;
rabbitmqctl set_permissions -p / $RABBITMQ_USER ".*" ".*" ".*" ;
echo "*** User '$RABBITMQ_USER' with password '$RABBITMQ_PASSWORD' completed. ***" ;
echo "*** Log in the WebUI at port 15672 (example: http:/localhost:15672) ***") &
# $@ is used to pass arguments to the rabbitmq-server command.
# For example if you use it like this: docker run -d rabbitmq arg1 arg2,
# it will be as you run in the container rabbitmq-server arg1 arg2
rabbitmq-server $@
This script also initialize and expose the RabbitMQ webadmin at port 15672.
1
cd /tmp ; wget http://localhost:15672/cli/rabbitmqadmin ; mv ./rabbitmqadmin /rabbitmqadmin ; chmod +x /rabbitmqadmin ;
I think these lines can be removed, as the admin command is already available inside the container.
– Joris Mans
Mar 28 '16 at 15:18
1
@JanuszSkonieczny Maybe something wrong with your line endings? I just tried the instructions again and it worked.
– Marco
Oct 30 '16 at 9:13
1
@JorisMans: Thanks, great suggestion, I edited the answer and removed the rabbitmqadmin installation.
– george.yord
Dec 14 '16 at 8:55
2
I get this error: /usr/local/bin/docker-entrypoint.sh: line 296: /init.sh: Permission denied. Did I miss something?
– cdimitroulas
Feb 6 '17 at 15:00
3
Does this actually work? On 3.6.6 I can't add any users without first having the node/application running. It looks like you are adding them before runningrabbitmq-server
.
– Derek
May 17 '17 at 4:28
|
show 13 more comments
Came up with a solution that suits my needs, leaving it here in case anybody else needs it.
Summary
The idea is to take a standard rabbitmq container with management plugin enabled and use it to create the required configuration, then export and use it to start new containers. The below solution creates a derived docker image but it also works to just mount the two files at runtime (e.g. using docker compose).
References
- the info I started from
- complete rabbitmq.config example
Components
- official rabbitmq image, management plugin version (rabbitmq:management)
custom image based on the original one, with this Dockerfile (using version 3.6.6):
FROM rabbitmq:3.6.6-management
ADD rabbitmq.config /etc/rabbitmq/
ADD definitions.json /etc/rabbitmq/
RUN chown rabbitmq:rabbitmq /etc/rabbitmq/rabbitmq.config /etc/rabbitmq/definitions.json
CMD ["rabbitmq-server"]
rabbitmq.config just tells rabbitmq to load definitions from the json file
definitions.json contains the users, vhosts, etc. and can be generated by the export function of the management web interface
rabbitmq.config example:
[
{rabbit, [
{loopback_users, }
]},
{rabbitmq_management, [
{load_definitions, "/etc/rabbitmq/definitions.json"}
]}
].
definitions.json example:
{
"rabbit_version": "3.6.6",
"users": [
{
"name": "user1",
"password_hash": "pass1",
"hashing_algorithm": "rabbit_password_hashing_sha256",
"tags": ""
},
{
"name": "adminuser",
"password_hash": "adminpass",
"hashing_algorithm": "rabbit_password_hashing_sha256",
"tags": "administrator"
}
],
"vhosts": [
{
"name": "/vhost1"
},
{
"name": "/vhost2"
}
],
"permissions": [
{
"user": "user1",
"vhost": "/vhost1",
"configure": ".*",
"write": ".*",
"read": ".*"
}
],
"parameters": ,
"policies": ,
"queues": ,
"exchanges": ,
"bindings":
}
Alternave version
Deriving a new docker image is just one solution and works best when portability is key, since it avoids including host-based file management in the picture.
In some situations using the official image and providing configuration files from storage local to the host might be preferred.
The rabbitmq.config and definitions.json files are produced the same way, then mounted at runtime.
Notes:
- I'm assuming they have been placed in /etc/so/ for the sake of these examples
- files need to either be world readable or owned by the rabbitmq user or group (numerical id inside the docker container is 999), this needs to be handled by the host's sysadmin
docker run example:
docker run --rm -it
-v /etc/so/rabbitmq.config:/etc/rabbitmq/rabbitmq.config:ro
-v /etc/so/definitions.json:/etc/rabbitmq/definitions.json:ro
rabbitmq:3.6-management
docker compose example:
version: '2.1'
services:
rabbitmq:
image: "rabbitmq:3.6-management"
ports:
- 5672:5672
- 15672:15672
volumes:
- /etc/so/rabbitmq.config:/etc/rabbitmq/rabbitmq.config:ro
- /etc/so/definitions.json:/etc/rabbitmq/definitions.json:ro
This is a great solution. @Tom.P adds a little to this with the definitions export from Rabbit. Combine the two and that should be the accepted answer. This worked for me!
– Kent Johnson
Oct 3 '17 at 14:15
@KentJohnson the fact that "definitions.json [...] can be generated by the export function of the management web interface" is already one of my points, that's how I did it too (the provided examples are just to get an idea right away)
– sudo
Oct 4 '17 at 13:27
2
Added chown command to make sure permissions are ok (thanks @Tom P.) and added an alternate solution that uses the official image + configuration files mounted at runtime
– sudo
Nov 29 '17 at 9:16
I've found this password hashing script which was pretty useful for me also gist.github.com/lukebakken/7b4da46ed9abb7ed14f7a60b49f9e52e
– jmhostalet
Sep 12 '18 at 7:03
Great solution. The main problem is to find documentation for the definitions.json. But you can do manually all the configuration and then export the definiton medium.com/@thomasdecaux/…
– Kleyson Rios
Nov 22 '18 at 15:11
add a comment |
I would like to add that sudo's response helped me a lot. But that it still missed a command to be added to the Dockerfile.
The rabbitmq.config and definitions.json file should be owned by the rabbitmq user & group. So after adding the files run chown.
The full Dockerfile in my case was the following:
FROM rabbitmq:3-management-alpine
ADD definitions.json /etc/rabbitmq/
ADD rabbitmq.config /etc/rabbitmq/
RUN chown rabbitmq:rabbitmq /etc/rabbitmq/rabbitmq.config /etc/rabbitmq/definitions.json
EXPOSE 4369 5671 5672 15671 15672 25672
CMD ["rabbitmq-server"]
The rabbitmq.config
file has the following content being a merge from the default image's config and the added definitions loading:
[
{ rabbit, [
{loopback_users, },
{ tcp_listeners, [ 5672 ]},
{ ssl_listeners, [ ]},
{ hipe_compile, false }
]},
{ rabbitmq_management, [
{ load_definitions, "/etc/rabbitmq/definitions.json"},
{ listeners, [
{ port, 15672 },
{ ssl, false }
]}
]}
].
The definitions file can be exported from the management interface in the overview tab.
So you would first create a normal 'empty' rabbitmq container. Define whatever users, exchanges and queues you like. Then enter the management interface, export the definitions and create your own image using the file as described above.
Downloading the definitions is the easiest way to get the right password hashes in the definitions file for your own passwords. If you do not wish to do that you should follow the instructions as noted here (https://www.rabbitmq.com/passwords.html) to generate the correct hashes.
I think you have enough content to make this an answer. So rather delete all the sentences that prevent this from being an answer (like saying: should be a comment). And that comment-needs-50 rule exists for good reasons.
– GhostCat
Aug 15 '17 at 14:18
1
Sorry those reputation roles are a sore point. There's been many times I felt like wanting to contribute something in a comment, an upvote and for everything I would get the 'this requires x reputation' message. Makes it a really high boundary to start contributing. In any case, thanks for the comment, I've made those changes. :)
– Tom P.
Aug 16 '17 at 8:33
The problem is that a very high number of people get accounts here. Too many of them give zip nada niente about quality. It only takes 1,2 well received questions to get to "upvote", and 1,2 well received answers and you are up to "comment".
– GhostCat
Aug 16 '17 at 8:35
3
@TomP. That was great recommending the export from Rabbit. That really saved me time! And it is completely accurate. This should be combined with sudo's answer as the accepted answer.
– Kent Johnson
Oct 3 '17 at 13:55
1
I've found this password hashing script which was pretty useful for me also gist.github.com/lukebakken/7b4da46ed9abb7ed14f7a60b49f9e52e
– jmhostalet
Sep 12 '18 at 7:03
add a comment |
The newest version of the RabbitMQ image on Dockerhub has in-built functionality for changing the default username / password from "guest" / "guest" to something else.
Simply set the environment variables "RABBITMQ_DEFAULT_USER" and "RABBITMQ_DEFAULT_PASS" when starting the image.
As a docker command, you would run the image like this:
docker run
-e RABBITMQ_DEFAULT_USER=test-user
-e RABBITMQ_DEFAULT_PASS=test-user
-p 5672:5672
rabbitmq
add a comment |
In my case sleep 5
solution above did not work because RabbitMQ startup time was much longer and not predictable. Posting solution which waits until RabbitMQ is up and running:
Dockerfile
FROM rabbitmq:3-management
ADD init.sh /
ADD config_rabbit.sh /
RUN chmod +x /init.sh /config_rabbit.sh
ENTRYPOINT ["/init.sh"]
init.sh
#!/bin/bash
# Launch config script in background
# Note there is no RabbitMQ Docker image support for executing commands after server (PID 1) is running (something like "ADD schema.sql /docker-entrypoint-initdb.d" in MySql image), so we are using this trick
/config_rabbit.sh &
# Launch
/docker-entrypoint.sh rabbitmq-server
config_rabbit.sh
#!/bin/bash
# This script needs to be executed just once
if [ -f /$0.completed ] ; then
echo "$0 `date` /$0.completed found, skipping run"
exit 0
fi
# Wait for RabbitMQ startup
for (( ; ; )) ; do
sleep 5
rabbitmqctl -q node_health_check > /dev/null 2>&1
if [ $? -eq 0 ] ; then
echo "$0 `date` rabbitmq is now running"
break
else
echo "$0 `date` waiting for rabbitmq startup"
fi
done
# Execute RabbitMQ config commands here
# Create user
rabbitmqctl add_user USER PASSWORD
rabbitmqctl set_permissions -p / USER ".*" ".*" ".*"
echo "$0 `date` user USER created"
# Create queue
rabbitmqadmin declare queue name=QUEUE durable=true
echo "$0 `date` queues created"
# Create mark so script is not ran again
touch /$0.completed
add a comment |
Here is an example of how I add an unprivileged user gg RUN useradd -d /home/gg -m -s /bin/bash gg
RUN echo gg:gg | chpasswd
RUN echo 'gg ALL=(ALL) NOPASSWD:ALL' >> /etc/sudoers.d/gg
RUN chmod 0440 /etc/sudoers.d/gg
add a comment |
I had to make a few changes to the script in the accepted answer to get it working based on the comments above.
Dockerfile
FROM rabbitmq
# Define environment variables.
ENV RABBITMQ_USER user
ENV RABBITMQ_PASSWORD user
ADD init.sh /init.sh
EXPOSE 15672
# Define default command
CMD ["/init.sh"]
init.sh
#!/bin/sh
( sleep 10 &&
rabbitmqctl add_user $RABBITMQ_USER $RABBITMQ_PASSWORD &&
rabbitmqctl set_user_tags $RABBITMQ_USER administrator &&
rabbitmqctl set_permissions -p / $RABBITMQ_USER ".*" ".*" ".*" ) &
rabbitmq-server
add a comment |
You can create a new image and use the rabbitmqctl command line.
For example using this Dockerfile:
FROM rabbitmq
# rabbitmqctl command requires to start the rabbitmq server
RUN service rabbitmq-server start
RUN /usr/lib/rabbitmq/bin/rabbitmqctl add_user test-user mypassword
RUN /usr/lib/rabbitmq/bin/rabbitmqctl add_vhost myvhost
RUN /usr/lib/rabbitmq/bin/rabbitmqctl set_permissions -p /myvhost test-user ".*" ".*" ".*"
And build the image using
sudo docker build -t anImageName .
I have not test my answer, I cannot use docker at work
2
It wont work, the build process is stateless, no daemons will be running on that process
– markcial
Apr 27 '16 at 11:13
add a comment |
Your Answer
StackExchange.ifUsing("editor", function () {
StackExchange.using("externalEditor", function () {
StackExchange.using("snippets", function () {
StackExchange.snippets.init();
});
});
}, "code-snippets");
StackExchange.ready(function() {
var channelOptions = {
tags: "".split(" "),
id: "1"
};
initTagRenderer("".split(" "), "".split(" "), channelOptions);
StackExchange.using("externalEditor", function() {
// Have to fire editor after snippets, if snippets enabled
if (StackExchange.settings.snippets.snippetsEnabled) {
StackExchange.using("snippets", function() {
createEditor();
});
}
else {
createEditor();
}
});
function createEditor() {
StackExchange.prepareEditor({
heartbeatType: 'answer',
autoActivateHeartbeat: false,
convertImagesToLinks: true,
noModals: true,
showLowRepImageUploadWarning: true,
reputationToPostImages: 10,
bindNavPrevention: true,
postfix: "",
imageUploader: {
brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
allowUrls: true
},
onDemand: true,
discardSelector: ".discard-answer"
,immediatelyShowMarkdownHelp:true
});
}
});
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
StackExchange.ready(
function () {
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f30747469%2fhow-to-add-initial-users-when-starting-a-rabbitmq-docker-container%23new-answer', 'question_page');
}
);
Post as a guest
Required, but never shown
8 Answers
8
active
oldest
votes
8 Answers
8
active
oldest
votes
active
oldest
votes
active
oldest
votes
You can create a simple Dockerfile that extends the functionality of the basic image and creates a default user.
The Docker file you need is the following:
FROM rabbitmq
# Define environment variables.
ENV RABBITMQ_USER user
ENV RABBITMQ_PASSWORD user
ADD init.sh /init.sh
EXPOSE 15672
# Define default command
CMD ["/init.sh"]
And the init.sh:
#!/bin/sh
# Create Rabbitmq user
( sleep 5 ;
rabbitmqctl add_user $RABBITMQ_USER $RABBITMQ_PASSWORD 2>/dev/null ;
rabbitmqctl set_user_tags $RABBITMQ_USER administrator ;
rabbitmqctl set_permissions -p / $RABBITMQ_USER ".*" ".*" ".*" ;
echo "*** User '$RABBITMQ_USER' with password '$RABBITMQ_PASSWORD' completed. ***" ;
echo "*** Log in the WebUI at port 15672 (example: http:/localhost:15672) ***") &
# $@ is used to pass arguments to the rabbitmq-server command.
# For example if you use it like this: docker run -d rabbitmq arg1 arg2,
# it will be as you run in the container rabbitmq-server arg1 arg2
rabbitmq-server $@
This script also initialize and expose the RabbitMQ webadmin at port 15672.
1
cd /tmp ; wget http://localhost:15672/cli/rabbitmqadmin ; mv ./rabbitmqadmin /rabbitmqadmin ; chmod +x /rabbitmqadmin ;
I think these lines can be removed, as the admin command is already available inside the container.
– Joris Mans
Mar 28 '16 at 15:18
1
@JanuszSkonieczny Maybe something wrong with your line endings? I just tried the instructions again and it worked.
– Marco
Oct 30 '16 at 9:13
1
@JorisMans: Thanks, great suggestion, I edited the answer and removed the rabbitmqadmin installation.
– george.yord
Dec 14 '16 at 8:55
2
I get this error: /usr/local/bin/docker-entrypoint.sh: line 296: /init.sh: Permission denied. Did I miss something?
– cdimitroulas
Feb 6 '17 at 15:00
3
Does this actually work? On 3.6.6 I can't add any users without first having the node/application running. It looks like you are adding them before runningrabbitmq-server
.
– Derek
May 17 '17 at 4:28
|
show 13 more comments
You can create a simple Dockerfile that extends the functionality of the basic image and creates a default user.
The Docker file you need is the following:
FROM rabbitmq
# Define environment variables.
ENV RABBITMQ_USER user
ENV RABBITMQ_PASSWORD user
ADD init.sh /init.sh
EXPOSE 15672
# Define default command
CMD ["/init.sh"]
And the init.sh:
#!/bin/sh
# Create Rabbitmq user
( sleep 5 ;
rabbitmqctl add_user $RABBITMQ_USER $RABBITMQ_PASSWORD 2>/dev/null ;
rabbitmqctl set_user_tags $RABBITMQ_USER administrator ;
rabbitmqctl set_permissions -p / $RABBITMQ_USER ".*" ".*" ".*" ;
echo "*** User '$RABBITMQ_USER' with password '$RABBITMQ_PASSWORD' completed. ***" ;
echo "*** Log in the WebUI at port 15672 (example: http:/localhost:15672) ***") &
# $@ is used to pass arguments to the rabbitmq-server command.
# For example if you use it like this: docker run -d rabbitmq arg1 arg2,
# it will be as you run in the container rabbitmq-server arg1 arg2
rabbitmq-server $@
This script also initialize and expose the RabbitMQ webadmin at port 15672.
1
cd /tmp ; wget http://localhost:15672/cli/rabbitmqadmin ; mv ./rabbitmqadmin /rabbitmqadmin ; chmod +x /rabbitmqadmin ;
I think these lines can be removed, as the admin command is already available inside the container.
– Joris Mans
Mar 28 '16 at 15:18
1
@JanuszSkonieczny Maybe something wrong with your line endings? I just tried the instructions again and it worked.
– Marco
Oct 30 '16 at 9:13
1
@JorisMans: Thanks, great suggestion, I edited the answer and removed the rabbitmqadmin installation.
– george.yord
Dec 14 '16 at 8:55
2
I get this error: /usr/local/bin/docker-entrypoint.sh: line 296: /init.sh: Permission denied. Did I miss something?
– cdimitroulas
Feb 6 '17 at 15:00
3
Does this actually work? On 3.6.6 I can't add any users without first having the node/application running. It looks like you are adding them before runningrabbitmq-server
.
– Derek
May 17 '17 at 4:28
|
show 13 more comments
You can create a simple Dockerfile that extends the functionality of the basic image and creates a default user.
The Docker file you need is the following:
FROM rabbitmq
# Define environment variables.
ENV RABBITMQ_USER user
ENV RABBITMQ_PASSWORD user
ADD init.sh /init.sh
EXPOSE 15672
# Define default command
CMD ["/init.sh"]
And the init.sh:
#!/bin/sh
# Create Rabbitmq user
( sleep 5 ;
rabbitmqctl add_user $RABBITMQ_USER $RABBITMQ_PASSWORD 2>/dev/null ;
rabbitmqctl set_user_tags $RABBITMQ_USER administrator ;
rabbitmqctl set_permissions -p / $RABBITMQ_USER ".*" ".*" ".*" ;
echo "*** User '$RABBITMQ_USER' with password '$RABBITMQ_PASSWORD' completed. ***" ;
echo "*** Log in the WebUI at port 15672 (example: http:/localhost:15672) ***") &
# $@ is used to pass arguments to the rabbitmq-server command.
# For example if you use it like this: docker run -d rabbitmq arg1 arg2,
# it will be as you run in the container rabbitmq-server arg1 arg2
rabbitmq-server $@
This script also initialize and expose the RabbitMQ webadmin at port 15672.
You can create a simple Dockerfile that extends the functionality of the basic image and creates a default user.
The Docker file you need is the following:
FROM rabbitmq
# Define environment variables.
ENV RABBITMQ_USER user
ENV RABBITMQ_PASSWORD user
ADD init.sh /init.sh
EXPOSE 15672
# Define default command
CMD ["/init.sh"]
And the init.sh:
#!/bin/sh
# Create Rabbitmq user
( sleep 5 ;
rabbitmqctl add_user $RABBITMQ_USER $RABBITMQ_PASSWORD 2>/dev/null ;
rabbitmqctl set_user_tags $RABBITMQ_USER administrator ;
rabbitmqctl set_permissions -p / $RABBITMQ_USER ".*" ".*" ".*" ;
echo "*** User '$RABBITMQ_USER' with password '$RABBITMQ_PASSWORD' completed. ***" ;
echo "*** Log in the WebUI at port 15672 (example: http:/localhost:15672) ***") &
# $@ is used to pass arguments to the rabbitmq-server command.
# For example if you use it like this: docker run -d rabbitmq arg1 arg2,
# it will be as you run in the container rabbitmq-server arg1 arg2
rabbitmq-server $@
This script also initialize and expose the RabbitMQ webadmin at port 15672.
edited Dec 14 '16 at 8:56
answered Jun 11 '15 at 7:06
george.yordgeorge.yord
1,14776
1,14776
1
cd /tmp ; wget http://localhost:15672/cli/rabbitmqadmin ; mv ./rabbitmqadmin /rabbitmqadmin ; chmod +x /rabbitmqadmin ;
I think these lines can be removed, as the admin command is already available inside the container.
– Joris Mans
Mar 28 '16 at 15:18
1
@JanuszSkonieczny Maybe something wrong with your line endings? I just tried the instructions again and it worked.
– Marco
Oct 30 '16 at 9:13
1
@JorisMans: Thanks, great suggestion, I edited the answer and removed the rabbitmqadmin installation.
– george.yord
Dec 14 '16 at 8:55
2
I get this error: /usr/local/bin/docker-entrypoint.sh: line 296: /init.sh: Permission denied. Did I miss something?
– cdimitroulas
Feb 6 '17 at 15:00
3
Does this actually work? On 3.6.6 I can't add any users without first having the node/application running. It looks like you are adding them before runningrabbitmq-server
.
– Derek
May 17 '17 at 4:28
|
show 13 more comments
1
cd /tmp ; wget http://localhost:15672/cli/rabbitmqadmin ; mv ./rabbitmqadmin /rabbitmqadmin ; chmod +x /rabbitmqadmin ;
I think these lines can be removed, as the admin command is already available inside the container.
– Joris Mans
Mar 28 '16 at 15:18
1
@JanuszSkonieczny Maybe something wrong with your line endings? I just tried the instructions again and it worked.
– Marco
Oct 30 '16 at 9:13
1
@JorisMans: Thanks, great suggestion, I edited the answer and removed the rabbitmqadmin installation.
– george.yord
Dec 14 '16 at 8:55
2
I get this error: /usr/local/bin/docker-entrypoint.sh: line 296: /init.sh: Permission denied. Did I miss something?
– cdimitroulas
Feb 6 '17 at 15:00
3
Does this actually work? On 3.6.6 I can't add any users without first having the node/application running. It looks like you are adding them before runningrabbitmq-server
.
– Derek
May 17 '17 at 4:28
1
1
cd /tmp ; wget http://localhost:15672/cli/rabbitmqadmin ; mv ./rabbitmqadmin /rabbitmqadmin ; chmod +x /rabbitmqadmin ;
I think these lines can be removed, as the admin command is already available inside the container.– Joris Mans
Mar 28 '16 at 15:18
cd /tmp ; wget http://localhost:15672/cli/rabbitmqadmin ; mv ./rabbitmqadmin /rabbitmqadmin ; chmod +x /rabbitmqadmin ;
I think these lines can be removed, as the admin command is already available inside the container.– Joris Mans
Mar 28 '16 at 15:18
1
1
@JanuszSkonieczny Maybe something wrong with your line endings? I just tried the instructions again and it worked.
– Marco
Oct 30 '16 at 9:13
@JanuszSkonieczny Maybe something wrong with your line endings? I just tried the instructions again and it worked.
– Marco
Oct 30 '16 at 9:13
1
1
@JorisMans: Thanks, great suggestion, I edited the answer and removed the rabbitmqadmin installation.
– george.yord
Dec 14 '16 at 8:55
@JorisMans: Thanks, great suggestion, I edited the answer and removed the rabbitmqadmin installation.
– george.yord
Dec 14 '16 at 8:55
2
2
I get this error: /usr/local/bin/docker-entrypoint.sh: line 296: /init.sh: Permission denied. Did I miss something?
– cdimitroulas
Feb 6 '17 at 15:00
I get this error: /usr/local/bin/docker-entrypoint.sh: line 296: /init.sh: Permission denied. Did I miss something?
– cdimitroulas
Feb 6 '17 at 15:00
3
3
Does this actually work? On 3.6.6 I can't add any users without first having the node/application running. It looks like you are adding them before running
rabbitmq-server
.– Derek
May 17 '17 at 4:28
Does this actually work? On 3.6.6 I can't add any users without first having the node/application running. It looks like you are adding them before running
rabbitmq-server
.– Derek
May 17 '17 at 4:28
|
show 13 more comments
Came up with a solution that suits my needs, leaving it here in case anybody else needs it.
Summary
The idea is to take a standard rabbitmq container with management plugin enabled and use it to create the required configuration, then export and use it to start new containers. The below solution creates a derived docker image but it also works to just mount the two files at runtime (e.g. using docker compose).
References
- the info I started from
- complete rabbitmq.config example
Components
- official rabbitmq image, management plugin version (rabbitmq:management)
custom image based on the original one, with this Dockerfile (using version 3.6.6):
FROM rabbitmq:3.6.6-management
ADD rabbitmq.config /etc/rabbitmq/
ADD definitions.json /etc/rabbitmq/
RUN chown rabbitmq:rabbitmq /etc/rabbitmq/rabbitmq.config /etc/rabbitmq/definitions.json
CMD ["rabbitmq-server"]
rabbitmq.config just tells rabbitmq to load definitions from the json file
definitions.json contains the users, vhosts, etc. and can be generated by the export function of the management web interface
rabbitmq.config example:
[
{rabbit, [
{loopback_users, }
]},
{rabbitmq_management, [
{load_definitions, "/etc/rabbitmq/definitions.json"}
]}
].
definitions.json example:
{
"rabbit_version": "3.6.6",
"users": [
{
"name": "user1",
"password_hash": "pass1",
"hashing_algorithm": "rabbit_password_hashing_sha256",
"tags": ""
},
{
"name": "adminuser",
"password_hash": "adminpass",
"hashing_algorithm": "rabbit_password_hashing_sha256",
"tags": "administrator"
}
],
"vhosts": [
{
"name": "/vhost1"
},
{
"name": "/vhost2"
}
],
"permissions": [
{
"user": "user1",
"vhost": "/vhost1",
"configure": ".*",
"write": ".*",
"read": ".*"
}
],
"parameters": ,
"policies": ,
"queues": ,
"exchanges": ,
"bindings":
}
Alternave version
Deriving a new docker image is just one solution and works best when portability is key, since it avoids including host-based file management in the picture.
In some situations using the official image and providing configuration files from storage local to the host might be preferred.
The rabbitmq.config and definitions.json files are produced the same way, then mounted at runtime.
Notes:
- I'm assuming they have been placed in /etc/so/ for the sake of these examples
- files need to either be world readable or owned by the rabbitmq user or group (numerical id inside the docker container is 999), this needs to be handled by the host's sysadmin
docker run example:
docker run --rm -it
-v /etc/so/rabbitmq.config:/etc/rabbitmq/rabbitmq.config:ro
-v /etc/so/definitions.json:/etc/rabbitmq/definitions.json:ro
rabbitmq:3.6-management
docker compose example:
version: '2.1'
services:
rabbitmq:
image: "rabbitmq:3.6-management"
ports:
- 5672:5672
- 15672:15672
volumes:
- /etc/so/rabbitmq.config:/etc/rabbitmq/rabbitmq.config:ro
- /etc/so/definitions.json:/etc/rabbitmq/definitions.json:ro
This is a great solution. @Tom.P adds a little to this with the definitions export from Rabbit. Combine the two and that should be the accepted answer. This worked for me!
– Kent Johnson
Oct 3 '17 at 14:15
@KentJohnson the fact that "definitions.json [...] can be generated by the export function of the management web interface" is already one of my points, that's how I did it too (the provided examples are just to get an idea right away)
– sudo
Oct 4 '17 at 13:27
2
Added chown command to make sure permissions are ok (thanks @Tom P.) and added an alternate solution that uses the official image + configuration files mounted at runtime
– sudo
Nov 29 '17 at 9:16
I've found this password hashing script which was pretty useful for me also gist.github.com/lukebakken/7b4da46ed9abb7ed14f7a60b49f9e52e
– jmhostalet
Sep 12 '18 at 7:03
Great solution. The main problem is to find documentation for the definitions.json. But you can do manually all the configuration and then export the definiton medium.com/@thomasdecaux/…
– Kleyson Rios
Nov 22 '18 at 15:11
add a comment |
Came up with a solution that suits my needs, leaving it here in case anybody else needs it.
Summary
The idea is to take a standard rabbitmq container with management plugin enabled and use it to create the required configuration, then export and use it to start new containers. The below solution creates a derived docker image but it also works to just mount the two files at runtime (e.g. using docker compose).
References
- the info I started from
- complete rabbitmq.config example
Components
- official rabbitmq image, management plugin version (rabbitmq:management)
custom image based on the original one, with this Dockerfile (using version 3.6.6):
FROM rabbitmq:3.6.6-management
ADD rabbitmq.config /etc/rabbitmq/
ADD definitions.json /etc/rabbitmq/
RUN chown rabbitmq:rabbitmq /etc/rabbitmq/rabbitmq.config /etc/rabbitmq/definitions.json
CMD ["rabbitmq-server"]
rabbitmq.config just tells rabbitmq to load definitions from the json file
definitions.json contains the users, vhosts, etc. and can be generated by the export function of the management web interface
rabbitmq.config example:
[
{rabbit, [
{loopback_users, }
]},
{rabbitmq_management, [
{load_definitions, "/etc/rabbitmq/definitions.json"}
]}
].
definitions.json example:
{
"rabbit_version": "3.6.6",
"users": [
{
"name": "user1",
"password_hash": "pass1",
"hashing_algorithm": "rabbit_password_hashing_sha256",
"tags": ""
},
{
"name": "adminuser",
"password_hash": "adminpass",
"hashing_algorithm": "rabbit_password_hashing_sha256",
"tags": "administrator"
}
],
"vhosts": [
{
"name": "/vhost1"
},
{
"name": "/vhost2"
}
],
"permissions": [
{
"user": "user1",
"vhost": "/vhost1",
"configure": ".*",
"write": ".*",
"read": ".*"
}
],
"parameters": ,
"policies": ,
"queues": ,
"exchanges": ,
"bindings":
}
Alternave version
Deriving a new docker image is just one solution and works best when portability is key, since it avoids including host-based file management in the picture.
In some situations using the official image and providing configuration files from storage local to the host might be preferred.
The rabbitmq.config and definitions.json files are produced the same way, then mounted at runtime.
Notes:
- I'm assuming they have been placed in /etc/so/ for the sake of these examples
- files need to either be world readable or owned by the rabbitmq user or group (numerical id inside the docker container is 999), this needs to be handled by the host's sysadmin
docker run example:
docker run --rm -it
-v /etc/so/rabbitmq.config:/etc/rabbitmq/rabbitmq.config:ro
-v /etc/so/definitions.json:/etc/rabbitmq/definitions.json:ro
rabbitmq:3.6-management
docker compose example:
version: '2.1'
services:
rabbitmq:
image: "rabbitmq:3.6-management"
ports:
- 5672:5672
- 15672:15672
volumes:
- /etc/so/rabbitmq.config:/etc/rabbitmq/rabbitmq.config:ro
- /etc/so/definitions.json:/etc/rabbitmq/definitions.json:ro
This is a great solution. @Tom.P adds a little to this with the definitions export from Rabbit. Combine the two and that should be the accepted answer. This worked for me!
– Kent Johnson
Oct 3 '17 at 14:15
@KentJohnson the fact that "definitions.json [...] can be generated by the export function of the management web interface" is already one of my points, that's how I did it too (the provided examples are just to get an idea right away)
– sudo
Oct 4 '17 at 13:27
2
Added chown command to make sure permissions are ok (thanks @Tom P.) and added an alternate solution that uses the official image + configuration files mounted at runtime
– sudo
Nov 29 '17 at 9:16
I've found this password hashing script which was pretty useful for me also gist.github.com/lukebakken/7b4da46ed9abb7ed14f7a60b49f9e52e
– jmhostalet
Sep 12 '18 at 7:03
Great solution. The main problem is to find documentation for the definitions.json. But you can do manually all the configuration and then export the definiton medium.com/@thomasdecaux/…
– Kleyson Rios
Nov 22 '18 at 15:11
add a comment |
Came up with a solution that suits my needs, leaving it here in case anybody else needs it.
Summary
The idea is to take a standard rabbitmq container with management plugin enabled and use it to create the required configuration, then export and use it to start new containers. The below solution creates a derived docker image but it also works to just mount the two files at runtime (e.g. using docker compose).
References
- the info I started from
- complete rabbitmq.config example
Components
- official rabbitmq image, management plugin version (rabbitmq:management)
custom image based on the original one, with this Dockerfile (using version 3.6.6):
FROM rabbitmq:3.6.6-management
ADD rabbitmq.config /etc/rabbitmq/
ADD definitions.json /etc/rabbitmq/
RUN chown rabbitmq:rabbitmq /etc/rabbitmq/rabbitmq.config /etc/rabbitmq/definitions.json
CMD ["rabbitmq-server"]
rabbitmq.config just tells rabbitmq to load definitions from the json file
definitions.json contains the users, vhosts, etc. and can be generated by the export function of the management web interface
rabbitmq.config example:
[
{rabbit, [
{loopback_users, }
]},
{rabbitmq_management, [
{load_definitions, "/etc/rabbitmq/definitions.json"}
]}
].
definitions.json example:
{
"rabbit_version": "3.6.6",
"users": [
{
"name": "user1",
"password_hash": "pass1",
"hashing_algorithm": "rabbit_password_hashing_sha256",
"tags": ""
},
{
"name": "adminuser",
"password_hash": "adminpass",
"hashing_algorithm": "rabbit_password_hashing_sha256",
"tags": "administrator"
}
],
"vhosts": [
{
"name": "/vhost1"
},
{
"name": "/vhost2"
}
],
"permissions": [
{
"user": "user1",
"vhost": "/vhost1",
"configure": ".*",
"write": ".*",
"read": ".*"
}
],
"parameters": ,
"policies": ,
"queues": ,
"exchanges": ,
"bindings":
}
Alternave version
Deriving a new docker image is just one solution and works best when portability is key, since it avoids including host-based file management in the picture.
In some situations using the official image and providing configuration files from storage local to the host might be preferred.
The rabbitmq.config and definitions.json files are produced the same way, then mounted at runtime.
Notes:
- I'm assuming they have been placed in /etc/so/ for the sake of these examples
- files need to either be world readable or owned by the rabbitmq user or group (numerical id inside the docker container is 999), this needs to be handled by the host's sysadmin
docker run example:
docker run --rm -it
-v /etc/so/rabbitmq.config:/etc/rabbitmq/rabbitmq.config:ro
-v /etc/so/definitions.json:/etc/rabbitmq/definitions.json:ro
rabbitmq:3.6-management
docker compose example:
version: '2.1'
services:
rabbitmq:
image: "rabbitmq:3.6-management"
ports:
- 5672:5672
- 15672:15672
volumes:
- /etc/so/rabbitmq.config:/etc/rabbitmq/rabbitmq.config:ro
- /etc/so/definitions.json:/etc/rabbitmq/definitions.json:ro
Came up with a solution that suits my needs, leaving it here in case anybody else needs it.
Summary
The idea is to take a standard rabbitmq container with management plugin enabled and use it to create the required configuration, then export and use it to start new containers. The below solution creates a derived docker image but it also works to just mount the two files at runtime (e.g. using docker compose).
References
- the info I started from
- complete rabbitmq.config example
Components
- official rabbitmq image, management plugin version (rabbitmq:management)
custom image based on the original one, with this Dockerfile (using version 3.6.6):
FROM rabbitmq:3.6.6-management
ADD rabbitmq.config /etc/rabbitmq/
ADD definitions.json /etc/rabbitmq/
RUN chown rabbitmq:rabbitmq /etc/rabbitmq/rabbitmq.config /etc/rabbitmq/definitions.json
CMD ["rabbitmq-server"]
rabbitmq.config just tells rabbitmq to load definitions from the json file
definitions.json contains the users, vhosts, etc. and can be generated by the export function of the management web interface
rabbitmq.config example:
[
{rabbit, [
{loopback_users, }
]},
{rabbitmq_management, [
{load_definitions, "/etc/rabbitmq/definitions.json"}
]}
].
definitions.json example:
{
"rabbit_version": "3.6.6",
"users": [
{
"name": "user1",
"password_hash": "pass1",
"hashing_algorithm": "rabbit_password_hashing_sha256",
"tags": ""
},
{
"name": "adminuser",
"password_hash": "adminpass",
"hashing_algorithm": "rabbit_password_hashing_sha256",
"tags": "administrator"
}
],
"vhosts": [
{
"name": "/vhost1"
},
{
"name": "/vhost2"
}
],
"permissions": [
{
"user": "user1",
"vhost": "/vhost1",
"configure": ".*",
"write": ".*",
"read": ".*"
}
],
"parameters": ,
"policies": ,
"queues": ,
"exchanges": ,
"bindings":
}
Alternave version
Deriving a new docker image is just one solution and works best when portability is key, since it avoids including host-based file management in the picture.
In some situations using the official image and providing configuration files from storage local to the host might be preferred.
The rabbitmq.config and definitions.json files are produced the same way, then mounted at runtime.
Notes:
- I'm assuming they have been placed in /etc/so/ for the sake of these examples
- files need to either be world readable or owned by the rabbitmq user or group (numerical id inside the docker container is 999), this needs to be handled by the host's sysadmin
docker run example:
docker run --rm -it
-v /etc/so/rabbitmq.config:/etc/rabbitmq/rabbitmq.config:ro
-v /etc/so/definitions.json:/etc/rabbitmq/definitions.json:ro
rabbitmq:3.6-management
docker compose example:
version: '2.1'
services:
rabbitmq:
image: "rabbitmq:3.6-management"
ports:
- 5672:5672
- 15672:15672
volumes:
- /etc/so/rabbitmq.config:/etc/rabbitmq/rabbitmq.config:ro
- /etc/so/definitions.json:/etc/rabbitmq/definitions.json:ro
edited Nov 29 '17 at 9:14
answered Feb 15 '17 at 13:52
sudosudo
35136
35136
This is a great solution. @Tom.P adds a little to this with the definitions export from Rabbit. Combine the two and that should be the accepted answer. This worked for me!
– Kent Johnson
Oct 3 '17 at 14:15
@KentJohnson the fact that "definitions.json [...] can be generated by the export function of the management web interface" is already one of my points, that's how I did it too (the provided examples are just to get an idea right away)
– sudo
Oct 4 '17 at 13:27
2
Added chown command to make sure permissions are ok (thanks @Tom P.) and added an alternate solution that uses the official image + configuration files mounted at runtime
– sudo
Nov 29 '17 at 9:16
I've found this password hashing script which was pretty useful for me also gist.github.com/lukebakken/7b4da46ed9abb7ed14f7a60b49f9e52e
– jmhostalet
Sep 12 '18 at 7:03
Great solution. The main problem is to find documentation for the definitions.json. But you can do manually all the configuration and then export the definiton medium.com/@thomasdecaux/…
– Kleyson Rios
Nov 22 '18 at 15:11
add a comment |
This is a great solution. @Tom.P adds a little to this with the definitions export from Rabbit. Combine the two and that should be the accepted answer. This worked for me!
– Kent Johnson
Oct 3 '17 at 14:15
@KentJohnson the fact that "definitions.json [...] can be generated by the export function of the management web interface" is already one of my points, that's how I did it too (the provided examples are just to get an idea right away)
– sudo
Oct 4 '17 at 13:27
2
Added chown command to make sure permissions are ok (thanks @Tom P.) and added an alternate solution that uses the official image + configuration files mounted at runtime
– sudo
Nov 29 '17 at 9:16
I've found this password hashing script which was pretty useful for me also gist.github.com/lukebakken/7b4da46ed9abb7ed14f7a60b49f9e52e
– jmhostalet
Sep 12 '18 at 7:03
Great solution. The main problem is to find documentation for the definitions.json. But you can do manually all the configuration and then export the definiton medium.com/@thomasdecaux/…
– Kleyson Rios
Nov 22 '18 at 15:11
This is a great solution. @Tom.P adds a little to this with the definitions export from Rabbit. Combine the two and that should be the accepted answer. This worked for me!
– Kent Johnson
Oct 3 '17 at 14:15
This is a great solution. @Tom.P adds a little to this with the definitions export from Rabbit. Combine the two and that should be the accepted answer. This worked for me!
– Kent Johnson
Oct 3 '17 at 14:15
@KentJohnson the fact that "definitions.json [...] can be generated by the export function of the management web interface" is already one of my points, that's how I did it too (the provided examples are just to get an idea right away)
– sudo
Oct 4 '17 at 13:27
@KentJohnson the fact that "definitions.json [...] can be generated by the export function of the management web interface" is already one of my points, that's how I did it too (the provided examples are just to get an idea right away)
– sudo
Oct 4 '17 at 13:27
2
2
Added chown command to make sure permissions are ok (thanks @Tom P.) and added an alternate solution that uses the official image + configuration files mounted at runtime
– sudo
Nov 29 '17 at 9:16
Added chown command to make sure permissions are ok (thanks @Tom P.) and added an alternate solution that uses the official image + configuration files mounted at runtime
– sudo
Nov 29 '17 at 9:16
I've found this password hashing script which was pretty useful for me also gist.github.com/lukebakken/7b4da46ed9abb7ed14f7a60b49f9e52e
– jmhostalet
Sep 12 '18 at 7:03
I've found this password hashing script which was pretty useful for me also gist.github.com/lukebakken/7b4da46ed9abb7ed14f7a60b49f9e52e
– jmhostalet
Sep 12 '18 at 7:03
Great solution. The main problem is to find documentation for the definitions.json. But you can do manually all the configuration and then export the definiton medium.com/@thomasdecaux/…
– Kleyson Rios
Nov 22 '18 at 15:11
Great solution. The main problem is to find documentation for the definitions.json. But you can do manually all the configuration and then export the definiton medium.com/@thomasdecaux/…
– Kleyson Rios
Nov 22 '18 at 15:11
add a comment |
I would like to add that sudo's response helped me a lot. But that it still missed a command to be added to the Dockerfile.
The rabbitmq.config and definitions.json file should be owned by the rabbitmq user & group. So after adding the files run chown.
The full Dockerfile in my case was the following:
FROM rabbitmq:3-management-alpine
ADD definitions.json /etc/rabbitmq/
ADD rabbitmq.config /etc/rabbitmq/
RUN chown rabbitmq:rabbitmq /etc/rabbitmq/rabbitmq.config /etc/rabbitmq/definitions.json
EXPOSE 4369 5671 5672 15671 15672 25672
CMD ["rabbitmq-server"]
The rabbitmq.config
file has the following content being a merge from the default image's config and the added definitions loading:
[
{ rabbit, [
{loopback_users, },
{ tcp_listeners, [ 5672 ]},
{ ssl_listeners, [ ]},
{ hipe_compile, false }
]},
{ rabbitmq_management, [
{ load_definitions, "/etc/rabbitmq/definitions.json"},
{ listeners, [
{ port, 15672 },
{ ssl, false }
]}
]}
].
The definitions file can be exported from the management interface in the overview tab.
So you would first create a normal 'empty' rabbitmq container. Define whatever users, exchanges and queues you like. Then enter the management interface, export the definitions and create your own image using the file as described above.
Downloading the definitions is the easiest way to get the right password hashes in the definitions file for your own passwords. If you do not wish to do that you should follow the instructions as noted here (https://www.rabbitmq.com/passwords.html) to generate the correct hashes.
I think you have enough content to make this an answer. So rather delete all the sentences that prevent this from being an answer (like saying: should be a comment). And that comment-needs-50 rule exists for good reasons.
– GhostCat
Aug 15 '17 at 14:18
1
Sorry those reputation roles are a sore point. There's been many times I felt like wanting to contribute something in a comment, an upvote and for everything I would get the 'this requires x reputation' message. Makes it a really high boundary to start contributing. In any case, thanks for the comment, I've made those changes. :)
– Tom P.
Aug 16 '17 at 8:33
The problem is that a very high number of people get accounts here. Too many of them give zip nada niente about quality. It only takes 1,2 well received questions to get to "upvote", and 1,2 well received answers and you are up to "comment".
– GhostCat
Aug 16 '17 at 8:35
3
@TomP. That was great recommending the export from Rabbit. That really saved me time! And it is completely accurate. This should be combined with sudo's answer as the accepted answer.
– Kent Johnson
Oct 3 '17 at 13:55
1
I've found this password hashing script which was pretty useful for me also gist.github.com/lukebakken/7b4da46ed9abb7ed14f7a60b49f9e52e
– jmhostalet
Sep 12 '18 at 7:03
add a comment |
I would like to add that sudo's response helped me a lot. But that it still missed a command to be added to the Dockerfile.
The rabbitmq.config and definitions.json file should be owned by the rabbitmq user & group. So after adding the files run chown.
The full Dockerfile in my case was the following:
FROM rabbitmq:3-management-alpine
ADD definitions.json /etc/rabbitmq/
ADD rabbitmq.config /etc/rabbitmq/
RUN chown rabbitmq:rabbitmq /etc/rabbitmq/rabbitmq.config /etc/rabbitmq/definitions.json
EXPOSE 4369 5671 5672 15671 15672 25672
CMD ["rabbitmq-server"]
The rabbitmq.config
file has the following content being a merge from the default image's config and the added definitions loading:
[
{ rabbit, [
{loopback_users, },
{ tcp_listeners, [ 5672 ]},
{ ssl_listeners, [ ]},
{ hipe_compile, false }
]},
{ rabbitmq_management, [
{ load_definitions, "/etc/rabbitmq/definitions.json"},
{ listeners, [
{ port, 15672 },
{ ssl, false }
]}
]}
].
The definitions file can be exported from the management interface in the overview tab.
So you would first create a normal 'empty' rabbitmq container. Define whatever users, exchanges and queues you like. Then enter the management interface, export the definitions and create your own image using the file as described above.
Downloading the definitions is the easiest way to get the right password hashes in the definitions file for your own passwords. If you do not wish to do that you should follow the instructions as noted here (https://www.rabbitmq.com/passwords.html) to generate the correct hashes.
I think you have enough content to make this an answer. So rather delete all the sentences that prevent this from being an answer (like saying: should be a comment). And that comment-needs-50 rule exists for good reasons.
– GhostCat
Aug 15 '17 at 14:18
1
Sorry those reputation roles are a sore point. There's been many times I felt like wanting to contribute something in a comment, an upvote and for everything I would get the 'this requires x reputation' message. Makes it a really high boundary to start contributing. In any case, thanks for the comment, I've made those changes. :)
– Tom P.
Aug 16 '17 at 8:33
The problem is that a very high number of people get accounts here. Too many of them give zip nada niente about quality. It only takes 1,2 well received questions to get to "upvote", and 1,2 well received answers and you are up to "comment".
– GhostCat
Aug 16 '17 at 8:35
3
@TomP. That was great recommending the export from Rabbit. That really saved me time! And it is completely accurate. This should be combined with sudo's answer as the accepted answer.
– Kent Johnson
Oct 3 '17 at 13:55
1
I've found this password hashing script which was pretty useful for me also gist.github.com/lukebakken/7b4da46ed9abb7ed14f7a60b49f9e52e
– jmhostalet
Sep 12 '18 at 7:03
add a comment |
I would like to add that sudo's response helped me a lot. But that it still missed a command to be added to the Dockerfile.
The rabbitmq.config and definitions.json file should be owned by the rabbitmq user & group. So after adding the files run chown.
The full Dockerfile in my case was the following:
FROM rabbitmq:3-management-alpine
ADD definitions.json /etc/rabbitmq/
ADD rabbitmq.config /etc/rabbitmq/
RUN chown rabbitmq:rabbitmq /etc/rabbitmq/rabbitmq.config /etc/rabbitmq/definitions.json
EXPOSE 4369 5671 5672 15671 15672 25672
CMD ["rabbitmq-server"]
The rabbitmq.config
file has the following content being a merge from the default image's config and the added definitions loading:
[
{ rabbit, [
{loopback_users, },
{ tcp_listeners, [ 5672 ]},
{ ssl_listeners, [ ]},
{ hipe_compile, false }
]},
{ rabbitmq_management, [
{ load_definitions, "/etc/rabbitmq/definitions.json"},
{ listeners, [
{ port, 15672 },
{ ssl, false }
]}
]}
].
The definitions file can be exported from the management interface in the overview tab.
So you would first create a normal 'empty' rabbitmq container. Define whatever users, exchanges and queues you like. Then enter the management interface, export the definitions and create your own image using the file as described above.
Downloading the definitions is the easiest way to get the right password hashes in the definitions file for your own passwords. If you do not wish to do that you should follow the instructions as noted here (https://www.rabbitmq.com/passwords.html) to generate the correct hashes.
I would like to add that sudo's response helped me a lot. But that it still missed a command to be added to the Dockerfile.
The rabbitmq.config and definitions.json file should be owned by the rabbitmq user & group. So after adding the files run chown.
The full Dockerfile in my case was the following:
FROM rabbitmq:3-management-alpine
ADD definitions.json /etc/rabbitmq/
ADD rabbitmq.config /etc/rabbitmq/
RUN chown rabbitmq:rabbitmq /etc/rabbitmq/rabbitmq.config /etc/rabbitmq/definitions.json
EXPOSE 4369 5671 5672 15671 15672 25672
CMD ["rabbitmq-server"]
The rabbitmq.config
file has the following content being a merge from the default image's config and the added definitions loading:
[
{ rabbit, [
{loopback_users, },
{ tcp_listeners, [ 5672 ]},
{ ssl_listeners, [ ]},
{ hipe_compile, false }
]},
{ rabbitmq_management, [
{ load_definitions, "/etc/rabbitmq/definitions.json"},
{ listeners, [
{ port, 15672 },
{ ssl, false }
]}
]}
].
The definitions file can be exported from the management interface in the overview tab.
So you would first create a normal 'empty' rabbitmq container. Define whatever users, exchanges and queues you like. Then enter the management interface, export the definitions and create your own image using the file as described above.
Downloading the definitions is the easiest way to get the right password hashes in the definitions file for your own passwords. If you do not wish to do that you should follow the instructions as noted here (https://www.rabbitmq.com/passwords.html) to generate the correct hashes.
edited Aug 16 '17 at 8:31
answered Aug 15 '17 at 13:43
Tom P.Tom P.
10016
10016
I think you have enough content to make this an answer. So rather delete all the sentences that prevent this from being an answer (like saying: should be a comment). And that comment-needs-50 rule exists for good reasons.
– GhostCat
Aug 15 '17 at 14:18
1
Sorry those reputation roles are a sore point. There's been many times I felt like wanting to contribute something in a comment, an upvote and for everything I would get the 'this requires x reputation' message. Makes it a really high boundary to start contributing. In any case, thanks for the comment, I've made those changes. :)
– Tom P.
Aug 16 '17 at 8:33
The problem is that a very high number of people get accounts here. Too many of them give zip nada niente about quality. It only takes 1,2 well received questions to get to "upvote", and 1,2 well received answers and you are up to "comment".
– GhostCat
Aug 16 '17 at 8:35
3
@TomP. That was great recommending the export from Rabbit. That really saved me time! And it is completely accurate. This should be combined with sudo's answer as the accepted answer.
– Kent Johnson
Oct 3 '17 at 13:55
1
I've found this password hashing script which was pretty useful for me also gist.github.com/lukebakken/7b4da46ed9abb7ed14f7a60b49f9e52e
– jmhostalet
Sep 12 '18 at 7:03
add a comment |
I think you have enough content to make this an answer. So rather delete all the sentences that prevent this from being an answer (like saying: should be a comment). And that comment-needs-50 rule exists for good reasons.
– GhostCat
Aug 15 '17 at 14:18
1
Sorry those reputation roles are a sore point. There's been many times I felt like wanting to contribute something in a comment, an upvote and for everything I would get the 'this requires x reputation' message. Makes it a really high boundary to start contributing. In any case, thanks for the comment, I've made those changes. :)
– Tom P.
Aug 16 '17 at 8:33
The problem is that a very high number of people get accounts here. Too many of them give zip nada niente about quality. It only takes 1,2 well received questions to get to "upvote", and 1,2 well received answers and you are up to "comment".
– GhostCat
Aug 16 '17 at 8:35
3
@TomP. That was great recommending the export from Rabbit. That really saved me time! And it is completely accurate. This should be combined with sudo's answer as the accepted answer.
– Kent Johnson
Oct 3 '17 at 13:55
1
I've found this password hashing script which was pretty useful for me also gist.github.com/lukebakken/7b4da46ed9abb7ed14f7a60b49f9e52e
– jmhostalet
Sep 12 '18 at 7:03
I think you have enough content to make this an answer. So rather delete all the sentences that prevent this from being an answer (like saying: should be a comment). And that comment-needs-50 rule exists for good reasons.
– GhostCat
Aug 15 '17 at 14:18
I think you have enough content to make this an answer. So rather delete all the sentences that prevent this from being an answer (like saying: should be a comment). And that comment-needs-50 rule exists for good reasons.
– GhostCat
Aug 15 '17 at 14:18
1
1
Sorry those reputation roles are a sore point. There's been many times I felt like wanting to contribute something in a comment, an upvote and for everything I would get the 'this requires x reputation' message. Makes it a really high boundary to start contributing. In any case, thanks for the comment, I've made those changes. :)
– Tom P.
Aug 16 '17 at 8:33
Sorry those reputation roles are a sore point. There's been many times I felt like wanting to contribute something in a comment, an upvote and for everything I would get the 'this requires x reputation' message. Makes it a really high boundary to start contributing. In any case, thanks for the comment, I've made those changes. :)
– Tom P.
Aug 16 '17 at 8:33
The problem is that a very high number of people get accounts here. Too many of them give zip nada niente about quality. It only takes 1,2 well received questions to get to "upvote", and 1,2 well received answers and you are up to "comment".
– GhostCat
Aug 16 '17 at 8:35
The problem is that a very high number of people get accounts here. Too many of them give zip nada niente about quality. It only takes 1,2 well received questions to get to "upvote", and 1,2 well received answers and you are up to "comment".
– GhostCat
Aug 16 '17 at 8:35
3
3
@TomP. That was great recommending the export from Rabbit. That really saved me time! And it is completely accurate. This should be combined with sudo's answer as the accepted answer.
– Kent Johnson
Oct 3 '17 at 13:55
@TomP. That was great recommending the export from Rabbit. That really saved me time! And it is completely accurate. This should be combined with sudo's answer as the accepted answer.
– Kent Johnson
Oct 3 '17 at 13:55
1
1
I've found this password hashing script which was pretty useful for me also gist.github.com/lukebakken/7b4da46ed9abb7ed14f7a60b49f9e52e
– jmhostalet
Sep 12 '18 at 7:03
I've found this password hashing script which was pretty useful for me also gist.github.com/lukebakken/7b4da46ed9abb7ed14f7a60b49f9e52e
– jmhostalet
Sep 12 '18 at 7:03
add a comment |
The newest version of the RabbitMQ image on Dockerhub has in-built functionality for changing the default username / password from "guest" / "guest" to something else.
Simply set the environment variables "RABBITMQ_DEFAULT_USER" and "RABBITMQ_DEFAULT_PASS" when starting the image.
As a docker command, you would run the image like this:
docker run
-e RABBITMQ_DEFAULT_USER=test-user
-e RABBITMQ_DEFAULT_PASS=test-user
-p 5672:5672
rabbitmq
add a comment |
The newest version of the RabbitMQ image on Dockerhub has in-built functionality for changing the default username / password from "guest" / "guest" to something else.
Simply set the environment variables "RABBITMQ_DEFAULT_USER" and "RABBITMQ_DEFAULT_PASS" when starting the image.
As a docker command, you would run the image like this:
docker run
-e RABBITMQ_DEFAULT_USER=test-user
-e RABBITMQ_DEFAULT_PASS=test-user
-p 5672:5672
rabbitmq
add a comment |
The newest version of the RabbitMQ image on Dockerhub has in-built functionality for changing the default username / password from "guest" / "guest" to something else.
Simply set the environment variables "RABBITMQ_DEFAULT_USER" and "RABBITMQ_DEFAULT_PASS" when starting the image.
As a docker command, you would run the image like this:
docker run
-e RABBITMQ_DEFAULT_USER=test-user
-e RABBITMQ_DEFAULT_PASS=test-user
-p 5672:5672
rabbitmq
The newest version of the RabbitMQ image on Dockerhub has in-built functionality for changing the default username / password from "guest" / "guest" to something else.
Simply set the environment variables "RABBITMQ_DEFAULT_USER" and "RABBITMQ_DEFAULT_PASS" when starting the image.
As a docker command, you would run the image like this:
docker run
-e RABBITMQ_DEFAULT_USER=test-user
-e RABBITMQ_DEFAULT_PASS=test-user
-p 5672:5672
rabbitmq
answered Oct 8 '18 at 11:40
AngryUbuntuNerdAngryUbuntuNerd
16416
16416
add a comment |
add a comment |
In my case sleep 5
solution above did not work because RabbitMQ startup time was much longer and not predictable. Posting solution which waits until RabbitMQ is up and running:
Dockerfile
FROM rabbitmq:3-management
ADD init.sh /
ADD config_rabbit.sh /
RUN chmod +x /init.sh /config_rabbit.sh
ENTRYPOINT ["/init.sh"]
init.sh
#!/bin/bash
# Launch config script in background
# Note there is no RabbitMQ Docker image support for executing commands after server (PID 1) is running (something like "ADD schema.sql /docker-entrypoint-initdb.d" in MySql image), so we are using this trick
/config_rabbit.sh &
# Launch
/docker-entrypoint.sh rabbitmq-server
config_rabbit.sh
#!/bin/bash
# This script needs to be executed just once
if [ -f /$0.completed ] ; then
echo "$0 `date` /$0.completed found, skipping run"
exit 0
fi
# Wait for RabbitMQ startup
for (( ; ; )) ; do
sleep 5
rabbitmqctl -q node_health_check > /dev/null 2>&1
if [ $? -eq 0 ] ; then
echo "$0 `date` rabbitmq is now running"
break
else
echo "$0 `date` waiting for rabbitmq startup"
fi
done
# Execute RabbitMQ config commands here
# Create user
rabbitmqctl add_user USER PASSWORD
rabbitmqctl set_permissions -p / USER ".*" ".*" ".*"
echo "$0 `date` user USER created"
# Create queue
rabbitmqadmin declare queue name=QUEUE durable=true
echo "$0 `date` queues created"
# Create mark so script is not ran again
touch /$0.completed
add a comment |
In my case sleep 5
solution above did not work because RabbitMQ startup time was much longer and not predictable. Posting solution which waits until RabbitMQ is up and running:
Dockerfile
FROM rabbitmq:3-management
ADD init.sh /
ADD config_rabbit.sh /
RUN chmod +x /init.sh /config_rabbit.sh
ENTRYPOINT ["/init.sh"]
init.sh
#!/bin/bash
# Launch config script in background
# Note there is no RabbitMQ Docker image support for executing commands after server (PID 1) is running (something like "ADD schema.sql /docker-entrypoint-initdb.d" in MySql image), so we are using this trick
/config_rabbit.sh &
# Launch
/docker-entrypoint.sh rabbitmq-server
config_rabbit.sh
#!/bin/bash
# This script needs to be executed just once
if [ -f /$0.completed ] ; then
echo "$0 `date` /$0.completed found, skipping run"
exit 0
fi
# Wait for RabbitMQ startup
for (( ; ; )) ; do
sleep 5
rabbitmqctl -q node_health_check > /dev/null 2>&1
if [ $? -eq 0 ] ; then
echo "$0 `date` rabbitmq is now running"
break
else
echo "$0 `date` waiting for rabbitmq startup"
fi
done
# Execute RabbitMQ config commands here
# Create user
rabbitmqctl add_user USER PASSWORD
rabbitmqctl set_permissions -p / USER ".*" ".*" ".*"
echo "$0 `date` user USER created"
# Create queue
rabbitmqadmin declare queue name=QUEUE durable=true
echo "$0 `date` queues created"
# Create mark so script is not ran again
touch /$0.completed
add a comment |
In my case sleep 5
solution above did not work because RabbitMQ startup time was much longer and not predictable. Posting solution which waits until RabbitMQ is up and running:
Dockerfile
FROM rabbitmq:3-management
ADD init.sh /
ADD config_rabbit.sh /
RUN chmod +x /init.sh /config_rabbit.sh
ENTRYPOINT ["/init.sh"]
init.sh
#!/bin/bash
# Launch config script in background
# Note there is no RabbitMQ Docker image support for executing commands after server (PID 1) is running (something like "ADD schema.sql /docker-entrypoint-initdb.d" in MySql image), so we are using this trick
/config_rabbit.sh &
# Launch
/docker-entrypoint.sh rabbitmq-server
config_rabbit.sh
#!/bin/bash
# This script needs to be executed just once
if [ -f /$0.completed ] ; then
echo "$0 `date` /$0.completed found, skipping run"
exit 0
fi
# Wait for RabbitMQ startup
for (( ; ; )) ; do
sleep 5
rabbitmqctl -q node_health_check > /dev/null 2>&1
if [ $? -eq 0 ] ; then
echo "$0 `date` rabbitmq is now running"
break
else
echo "$0 `date` waiting for rabbitmq startup"
fi
done
# Execute RabbitMQ config commands here
# Create user
rabbitmqctl add_user USER PASSWORD
rabbitmqctl set_permissions -p / USER ".*" ".*" ".*"
echo "$0 `date` user USER created"
# Create queue
rabbitmqadmin declare queue name=QUEUE durable=true
echo "$0 `date` queues created"
# Create mark so script is not ran again
touch /$0.completed
In my case sleep 5
solution above did not work because RabbitMQ startup time was much longer and not predictable. Posting solution which waits until RabbitMQ is up and running:
Dockerfile
FROM rabbitmq:3-management
ADD init.sh /
ADD config_rabbit.sh /
RUN chmod +x /init.sh /config_rabbit.sh
ENTRYPOINT ["/init.sh"]
init.sh
#!/bin/bash
# Launch config script in background
# Note there is no RabbitMQ Docker image support for executing commands after server (PID 1) is running (something like "ADD schema.sql /docker-entrypoint-initdb.d" in MySql image), so we are using this trick
/config_rabbit.sh &
# Launch
/docker-entrypoint.sh rabbitmq-server
config_rabbit.sh
#!/bin/bash
# This script needs to be executed just once
if [ -f /$0.completed ] ; then
echo "$0 `date` /$0.completed found, skipping run"
exit 0
fi
# Wait for RabbitMQ startup
for (( ; ; )) ; do
sleep 5
rabbitmqctl -q node_health_check > /dev/null 2>&1
if [ $? -eq 0 ] ; then
echo "$0 `date` rabbitmq is now running"
break
else
echo "$0 `date` waiting for rabbitmq startup"
fi
done
# Execute RabbitMQ config commands here
# Create user
rabbitmqctl add_user USER PASSWORD
rabbitmqctl set_permissions -p / USER ".*" ".*" ".*"
echo "$0 `date` user USER created"
# Create queue
rabbitmqadmin declare queue name=QUEUE durable=true
echo "$0 `date` queues created"
# Create mark so script is not ran again
touch /$0.completed
edited Sep 15 '18 at 5:08
answered Sep 13 '18 at 8:32
MartinMartin
192
192
add a comment |
add a comment |
Here is an example of how I add an unprivileged user gg RUN useradd -d /home/gg -m -s /bin/bash gg
RUN echo gg:gg | chpasswd
RUN echo 'gg ALL=(ALL) NOPASSWD:ALL' >> /etc/sudoers.d/gg
RUN chmod 0440 /etc/sudoers.d/gg
add a comment |
Here is an example of how I add an unprivileged user gg RUN useradd -d /home/gg -m -s /bin/bash gg
RUN echo gg:gg | chpasswd
RUN echo 'gg ALL=(ALL) NOPASSWD:ALL' >> /etc/sudoers.d/gg
RUN chmod 0440 /etc/sudoers.d/gg
add a comment |
Here is an example of how I add an unprivileged user gg RUN useradd -d /home/gg -m -s /bin/bash gg
RUN echo gg:gg | chpasswd
RUN echo 'gg ALL=(ALL) NOPASSWD:ALL' >> /etc/sudoers.d/gg
RUN chmod 0440 /etc/sudoers.d/gg
Here is an example of how I add an unprivileged user gg RUN useradd -d /home/gg -m -s /bin/bash gg
RUN echo gg:gg | chpasswd
RUN echo 'gg ALL=(ALL) NOPASSWD:ALL' >> /etc/sudoers.d/gg
RUN chmod 0440 /etc/sudoers.d/gg
answered Jun 10 '15 at 5:29
user2915097user2915097
13.5k43041
13.5k43041
add a comment |
add a comment |
I had to make a few changes to the script in the accepted answer to get it working based on the comments above.
Dockerfile
FROM rabbitmq
# Define environment variables.
ENV RABBITMQ_USER user
ENV RABBITMQ_PASSWORD user
ADD init.sh /init.sh
EXPOSE 15672
# Define default command
CMD ["/init.sh"]
init.sh
#!/bin/sh
( sleep 10 &&
rabbitmqctl add_user $RABBITMQ_USER $RABBITMQ_PASSWORD &&
rabbitmqctl set_user_tags $RABBITMQ_USER administrator &&
rabbitmqctl set_permissions -p / $RABBITMQ_USER ".*" ".*" ".*" ) &
rabbitmq-server
add a comment |
I had to make a few changes to the script in the accepted answer to get it working based on the comments above.
Dockerfile
FROM rabbitmq
# Define environment variables.
ENV RABBITMQ_USER user
ENV RABBITMQ_PASSWORD user
ADD init.sh /init.sh
EXPOSE 15672
# Define default command
CMD ["/init.sh"]
init.sh
#!/bin/sh
( sleep 10 &&
rabbitmqctl add_user $RABBITMQ_USER $RABBITMQ_PASSWORD &&
rabbitmqctl set_user_tags $RABBITMQ_USER administrator &&
rabbitmqctl set_permissions -p / $RABBITMQ_USER ".*" ".*" ".*" ) &
rabbitmq-server
add a comment |
I had to make a few changes to the script in the accepted answer to get it working based on the comments above.
Dockerfile
FROM rabbitmq
# Define environment variables.
ENV RABBITMQ_USER user
ENV RABBITMQ_PASSWORD user
ADD init.sh /init.sh
EXPOSE 15672
# Define default command
CMD ["/init.sh"]
init.sh
#!/bin/sh
( sleep 10 &&
rabbitmqctl add_user $RABBITMQ_USER $RABBITMQ_PASSWORD &&
rabbitmqctl set_user_tags $RABBITMQ_USER administrator &&
rabbitmqctl set_permissions -p / $RABBITMQ_USER ".*" ".*" ".*" ) &
rabbitmq-server
I had to make a few changes to the script in the accepted answer to get it working based on the comments above.
Dockerfile
FROM rabbitmq
# Define environment variables.
ENV RABBITMQ_USER user
ENV RABBITMQ_PASSWORD user
ADD init.sh /init.sh
EXPOSE 15672
# Define default command
CMD ["/init.sh"]
init.sh
#!/bin/sh
( sleep 10 &&
rabbitmqctl add_user $RABBITMQ_USER $RABBITMQ_PASSWORD &&
rabbitmqctl set_user_tags $RABBITMQ_USER administrator &&
rabbitmqctl set_permissions -p / $RABBITMQ_USER ".*" ".*" ".*" ) &
rabbitmq-server
answered Nov 20 '18 at 23:42
FiaccFiacc
1,0541222
1,0541222
add a comment |
add a comment |
You can create a new image and use the rabbitmqctl command line.
For example using this Dockerfile:
FROM rabbitmq
# rabbitmqctl command requires to start the rabbitmq server
RUN service rabbitmq-server start
RUN /usr/lib/rabbitmq/bin/rabbitmqctl add_user test-user mypassword
RUN /usr/lib/rabbitmq/bin/rabbitmqctl add_vhost myvhost
RUN /usr/lib/rabbitmq/bin/rabbitmqctl set_permissions -p /myvhost test-user ".*" ".*" ".*"
And build the image using
sudo docker build -t anImageName .
I have not test my answer, I cannot use docker at work
2
It wont work, the build process is stateless, no daemons will be running on that process
– markcial
Apr 27 '16 at 11:13
add a comment |
You can create a new image and use the rabbitmqctl command line.
For example using this Dockerfile:
FROM rabbitmq
# rabbitmqctl command requires to start the rabbitmq server
RUN service rabbitmq-server start
RUN /usr/lib/rabbitmq/bin/rabbitmqctl add_user test-user mypassword
RUN /usr/lib/rabbitmq/bin/rabbitmqctl add_vhost myvhost
RUN /usr/lib/rabbitmq/bin/rabbitmqctl set_permissions -p /myvhost test-user ".*" ".*" ".*"
And build the image using
sudo docker build -t anImageName .
I have not test my answer, I cannot use docker at work
2
It wont work, the build process is stateless, no daemons will be running on that process
– markcial
Apr 27 '16 at 11:13
add a comment |
You can create a new image and use the rabbitmqctl command line.
For example using this Dockerfile:
FROM rabbitmq
# rabbitmqctl command requires to start the rabbitmq server
RUN service rabbitmq-server start
RUN /usr/lib/rabbitmq/bin/rabbitmqctl add_user test-user mypassword
RUN /usr/lib/rabbitmq/bin/rabbitmqctl add_vhost myvhost
RUN /usr/lib/rabbitmq/bin/rabbitmqctl set_permissions -p /myvhost test-user ".*" ".*" ".*"
And build the image using
sudo docker build -t anImageName .
I have not test my answer, I cannot use docker at work
You can create a new image and use the rabbitmqctl command line.
For example using this Dockerfile:
FROM rabbitmq
# rabbitmqctl command requires to start the rabbitmq server
RUN service rabbitmq-server start
RUN /usr/lib/rabbitmq/bin/rabbitmqctl add_user test-user mypassword
RUN /usr/lib/rabbitmq/bin/rabbitmqctl add_vhost myvhost
RUN /usr/lib/rabbitmq/bin/rabbitmqctl set_permissions -p /myvhost test-user ".*" ".*" ".*"
And build the image using
sudo docker build -t anImageName .
I have not test my answer, I cannot use docker at work
edited Jun 10 '15 at 8:46
answered Jun 10 '15 at 7:54
Nicolas LabrotNicolas Labrot
2,8821828
2,8821828
2
It wont work, the build process is stateless, no daemons will be running on that process
– markcial
Apr 27 '16 at 11:13
add a comment |
2
It wont work, the build process is stateless, no daemons will be running on that process
– markcial
Apr 27 '16 at 11:13
2
2
It wont work, the build process is stateless, no daemons will be running on that process
– markcial
Apr 27 '16 at 11:13
It wont work, the build process is stateless, no daemons will be running on that process
– markcial
Apr 27 '16 at 11:13
add a comment |
Thanks for contributing an answer to Stack Overflow!
- Please be sure to answer the question. Provide details and share your research!
But avoid …
- Asking for help, clarification, or responding to other answers.
- Making statements based on opinion; back them up with references or personal experience.
To learn more, see our tips on writing great answers.
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
StackExchange.ready(
function () {
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f30747469%2fhow-to-add-initial-users-when-starting-a-rabbitmq-docker-container%23new-answer', 'question_page');
}
);
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
1
In respect to the answer i got wrote a small blogpost writing down the process and files involved. mpas.github.io/post/2015/06/docker-rabbitmq-default-users
– Marco
Jun 11 '15 at 11:44
1
Blog post link update mpas.github.io/2015/06/11/…
– Janusz Skonieczny
Oct 28 '16 at 14:13