Docker Community Forums

Share and learn in the Docker community.

Docker service keep failing


(Skem58) #1

I am new to docker, so probably I am not doing right. But I would like to ask your thought.
I am just trying to create a simple mysql service on docker swarm 1.12.1 with volume.
I am using mysql image pulled from docker hub.
docker service create --name second-mysql --replicas 2 -p 3306:3306 --env MYSQL_ROOT_PASSWORD=mypwd -mount type=bind,source=/storage/mysql1/datadir,target=/var/lib/mysql mysql

services were created, however second replica is failing saying “task:non-zero exit(1)” when I did docker service ps first-mysql. I looked at syslog, and “fatal task error” … If I created mysql service without volume, both services are working. What am I doing wrong? I really appreciate it.

$ docker service ps second-mysql
ID NAME IMAGE NODE DESIRED STATE CURRENT STATE ERROR
8vf3djjn5b0bqb3chzg972ri7 second-mysql.1 mysql MSLNXUB001 Running Running about an hour ago
3plr69b4camd7fv7brc1at0n8 second-mysql.2 mysql MSLNXUB001 Running Running 38 seconds ago
cbyejbkvhegk85ly5nn2f2e6f _ second-mysql.2 mysql MSLNXUB001 Shutdown Failed 44 seconds ago "task: non-zero exit (1)"
8zapo4jah6lwr9b0si529crkv _ second-mysql.2 mysql MSLNXUB001 Shutdown Failed 2 minutes ago "task: non-zero exit (1)"
6gcm82bsgqg28oel587m1qxdu _ second-mysql.2 mysql MSLNXUB001 Shutdown Failed 4 minutes ago "task: non-zero exit (1)"
brq2k6o7mgmpoz3q6rkey8npn _ second-mysql.2 mysql MSLNXUB001 Shutdown Failed 6 minutes ago “task: non-zero exit (1)”

Thanks,


(Ktwalrus) #2

I think it is a little too much to expect two mysql replicas that could be running on the same host to share the same host directory for each replicas database. Each replica needs to have its own persistent data for each replicas database.

You need to run 2 mysql services with only a single replica in each service using a different host directory for each service, I think. If you need to keep the databases in sync, you need to set up some sort of mysql replication. And, provide your own proxy service for clients to use the 2 mysql services.

Remember, the clients of your 2 replica mysql service would load balance the SQL queries sent to your service so updates would only be applied to one database or the other. This obviously wouldn’t work in production.


(Skem58) #3

I was thinking more so active passive like database clustering with shared storage. But yes that make sense.
So that means we don’t do with --replicas for mysql services then.

Also what is the best practice for production usage? How others are doing…


(John Wang) #4

–replicas in docker service create means to replicate a container. It can’t replicate the MySQL database in the container this way. If you want to do a replication of MySQL, you may make your own images of MYSQL replication. When you launch a MySQL replication container, it will replicate the master of MySQL database. Likewise, you may create images for active-passive MySQL cluster, which requires cluster resource manager and more components. Both the active and passive MySQL database share the same database file. I hope it is helpful.