I am new to docker, and I have a problem. I want to gain affinity and exchanging data between two nodes in docker swarm.
(example ip)
I have one as manager: 192.168.10.1
and worker on: 192.168.10.2
They are already connected.
I have wrote docker-compose.yml
file to create new service with postgres DB, and
manager yml file looks like:
version: '3.1'
services:
db:
image: postgres
environment:
POSTGRES_DB: My_DB
POSTGRES_USER: My_DB_User
POSTGRES_PASSWORD: My_DB_Password
PG_DATA: /var/lib/postgresql/data/pgdatai
deploy:
placement:
constraints:
- node.role == manager
- node.labels.type == queue
adminer:
image: adminer
ports:
- 8080:8080
and worker:
version: '3.1'
services:
db:
image: postgres
environment:
POSTGRES_DB: My_DB
POSTGRES_USER: My_DB_User
POSTGRES_PASSWORD: My_DB_Password
PG_DATA: /var/lib/postgresql/data/pgdatai
deploy:
placement:
constraints:
- node.role == worker
- node.labels.type == queue
adminer:
image: adminer
ports:
- 8080:8080
And I dont have any stack on my machines. Doing command below (not sure if correct one) I have an error: yaml: line 2: did not find expected key
docker stack deploy --compose-file docker-compose.yml my_hostname
my hostname is read by me from command docker node ls
in manager machine
Maybe someone has dealed with a very similiar issue and goals and can give me a guidance. I have looked at several demos on internet, but I found those a little bit useless. I would appreciate any help and guides of how I can achieve this "backup"
Ok, so I now understand yaml more. For anyone else, who occures similar problems:
1) check your writing in yml file. You should take double care about white marks.
2) I reconfigured yml file:
version: '3'
services:
db:
image: postgres
environment:
POSTGRES_DB: db_db
POSTGRES_USER: db_user
POSTGRES_PASSWORD: db_pass
PG_DATA: /var/lib/postgresql/data/pgdatai
expose:
- "5432"
ports:
- "5432:5432"
volumes:
- /var/lib/postresql/db/
deploy:
placement:
constraints:
- node.hostname == vmAPI1
3) I used command for putting service to running swarm:
docker stack deploy --compose-file docker-compose.yml name_of_your_manager_swarm