Reputation: 2939
I am trying to create a rabbitmq cluster using docker, based on the details provided in these two links below, I have it starting up, but not sure how to start up an image/container after I have removed it again.
https://www.youtube.com/watch?v=w2kGd2VRJWE
https://www.youtube.com/watch?v=FzqjtU2x6YA
The second video he goes through stopping a node with this command (Excuse the name, not sure yet how to make it more succinct)
docker rm -f rabbitcluster_rabbit_node_3_1
So my question is, how do I start up the 3rd one that i just remove above? at the moment I have tried this command which is the images name but get is starting separately it would seem.
docker run -d rabbitcluster_rabbit_node_3
Can I use anything from the docker-compose.yml or am I going to have to use docker run, as it seems disconnected from the docker-compose.yml file now!?
This is the docker-compose.yml that I have written
version: "3.9"
services:
rabbit_node_1:
build: .
hostname: rabbit-1
environment:
- RABBITMQ_ERLANG_COOKIE = "ABCDYJLFQNTHDRZEPLOZ"
- RABBIT_NODENAME = rabbit1
- RABBITMQ_CONFIG_FILE = /etc/rabbitmq/rabbitmq.conf
- RABBITMQ_SERVER_ADDITIONAL_ERL_ARGS = -rabbit log [{console,[{level,debug}]}]
ports:
- 8081:15672
- 5672:5672
- 4369:4369
rabbit_node_2:
build: .
hostname: rabbit-2
# Don't start any of these until rabbit1 is up
depends_on:
- rabbit1
environment:
- RABBITMQ_ERLANG_COOKIE = "ABCDYJLFQNTHDRZEPLOZ"
- RABBIT_NODENAME = rabbit2
- RABBITMQ_CONFIG_FILE = /etc/rabbitmq/rabbitmq.conf
- RABBITMQ_SERVER_ADDITIONAL_ERL_ARGS = -rabbit log [{console,[{level,debug}]}]
ports:
- 8082:15672
rabbit_node_3:
build: .
hostname: rabbit-3
# Don't start any of these until rabbit1 is up
depends_on:
- rabbit1
environment:
- RABBITMQ_ERLANG_COOKIE = "ABCDYJLFQNTHDRZEPLOZ"
- RABBIT_NODENAME = rabbit3
- RABBITMQ_CONFIG_FILE = /etc/rabbitmq/rabbitmq.conf
- RABBITMQ_SERVER_ADDITIONAL_ERL_ARGS = -rabbit log [{console,[{level,debug}]}]
ports:
- 8083:15672
# docker network create rabbitmq-cluster
networks:
default:
name: rabbitmq-cluster
This is the Dockerfile
FROM rabbitmq:3.9-management
COPY rabbitmq.conf /etc/rabbitmq/rabbitmq.conf
COPY definitions.json /etc/rabbitmq/definitions.json
COPY .erlang.cookie /var/lib/rabbitmq/.erlang.cookie
RUN chmod 700 /var/lib/rabbitmq/.erlang.cookie
This is the rabbitmq.conf
loopback_users.guest = false
listeners.tcp.default = 5672
management.listener.port = 15672
management.listener.ssl = false
management.load_definitions = /etc/rabbitmq/definitions.json
cluster_name = cluster1
cluster_formation.peer_discovery_backend = rabbit_peer_discovery_classic_config
cluster_formation.classic_config.nodes.1 = rabbit@rabbit-1
cluster_formation.classic_config.nodes.2 = rabbit@rabbit-2
cluster_formation.classic_config.nodes.3 = rabbit@rabbit-3
finally this is the rabbitmq definitions.json file
{
"users": [
{
"name": "andrew",
"password": "test",
"tags": "administrator"
}
],
"vhosts": [
{
"name": "/"
}
],
"permissions": [
{
"user": "andrew",
"vhost": "/",
"configure": ".*",
"write": ".*",
"read": ".*"
}
],
"parameters": [],
"policies": [],
"exchanges": [
{
"name": "test.exchange",
"vhost": "/",
"type": "direct",
"durable": true,
"auto_delete": false,
"internal": false,
"arguments": {}
}
],
"queues": [
{
"name": "test.queue",
"vhost": "/",
"durable": true,
"auto_delete": false,
"arguments": {}
}
],
"bindings": [
{
"source": "test.exchange",
"vhost": "/",
"destination": "test.queue",
"destination_type": "queue",
"routing_key": "",
"arguments": {}
}
]
}
Upvotes: 0
Views: 599
Reputation: 2989
The command docker rm -f
(forcibly) removes a container. You cannot start it anymore after that, because it no longer exists.
If you want to create a new container from the service rabbit_node_3
in your docker-compose
file, you need to use the docker-compose
command from within the directory where your docker-compose.yml
resides:
docker-compose up -d rabbit_node_3
Where:
up
tells docker-compose to create containers from the named service (rabbit_node_3
)-d
tells docker-compose that you do not want to attach your terminal to stdout
and stderr
of the container started with this command. It would just go in the background and free your terminal for other tasksUpvotes: 1