1

I am running a db2 container sample using this docker command. Reference docker image

docker run -itd --name mydb2 --privileged=true -p 50000:50000 -e LICENSE=accept -e DB2INST1_PASSWORD=Notallowed1! -e DBNAME=testdb ibmcom/db2

It is working. If I remove the --privileged=true I will get below error.

connection error

So, --privileged=true is mandatory.

I tried add this to docker swarm as a service using this command.

docker service create --name db2luw_1 --privileged=true -p target=50000 -e LICENSE=accept -e 'DB2INST1_PASSWORD=Notallowed1!' -e DBNAME=testdb -d ibmcom/db2

But getting this error.

unknown flag: --privileged
See 'docker service create --help'.

How to run this container in docker swarm? Removing the --privileged is creating the service but useless as we will get connection error.I tested that.

uday
  • 352
  • 10
  • 30

2 Answers2

1

As already said in the answer by mac, swarm mode does not support privileged mode still.

There is a hacky workaround though if you want to run privileged containers in swarm today: Just create an intermediate service which has access to the docker socket of the host, and then run a privileged container from there.

Something like the following should work:

 docker service create \
   --name mydb2-wrapper \
   --mount type=bind,source=/var/run/docker.sock,target=/var/run/docker.sock,ro \
   docker \
   docker run --name mydb2 --privileged=true -p 50000:50000 -e LICENSE=accept -e DB2INST1_PASSWORD=Notallowed1! -e DBNAME=testdb ibmcom/db2
user11784
  • 11
  • 1
0

Creating a service means you run your containers in swarm mode. See How services work in Docker documentation on that.

Unfortunately privileged mode doesn't work in swarm mode. As you see here the --privileged option isn't available when running docker service create

mac
  • 1
  • 1