Bug #91405 Can't update/remove mysql on host system if you have running mysql in docker
Submitted: 25 Jun 2018 10:20 Modified: 7 May 17:58
Reporter: Evgeniy Patlan (OCA) Email Updates:
Status: Closed Impact on me:
Category:MySQL Server: Packaging Severity:S2 (Serious)
Version:8.0.1, 5.7.22 OS:Any
Assigned to: Lars Tangvald CPU Architecture:Any

[25 Jun 2018 10:20] Evgeniy Patlan
If you have running mysql in docker and on host system it is not possible to update/remove mysql on host system

dpkg: error processing package mysql-community-server (--purge):
 subprocess installed post-removal script returned error exit status 1

ubuntu@ubuntu-xenial:~$ ps -ef | grep "/usr/sbin/mysqld"
999      15261 15207  0 09:28 ?        00:00:00 /usr/sbin/mysqld --basedir=/usr --datadir=/var/lib/mysql --plugin-dir=/usr/lib64/mysql/plugin --pid-file=/var/run/mysqld/mysqld.pid --socket=/var/lib/mysql/mysql.sock
ubuntu   15991  1747  0 09:53 pts/0    00:00:00 grep --color=auto /usr/sbin/mysqld

So one of these processes is running in docker and another one on host machine.

Command `ps -ef | grep "/usr/sbin/mysqld"` is a part of postrm and preinst script 

It is in procedure: get_pcount

How to repeat:
Install mysql, install docker, create container with running mysql in it, try to update/remove mysql on host system

Suggested fix:
There are several ways to fix:
- use Debian's start-stop-daemon infrastructure
- detect if it is docker: for example
  * user 999
  * detect if it is docker from mount info of the preocess
/proc/15261/task/15261/mounts:overlay / overlay rw,relatime,lowerdir=/var/lib/docker/overlay2/l/523HPF6XTNGXSEIVPXNHRDFEWQ:/var/lib/docker/overlay2/l/F2FQL65M4G7IBRHOYH36T2IZXX:/var/lib/docker/overlay2/l/OUWX435LOMCHECGN6SSFDTKQ2P,upperdir=/var/lib/docker/overlay2/30b56fbfbfabba73f03df67c83d4497f86015baeebbe53c72bce42db332fe08a/diff,workdir=/var/lib/docker/overlay2/30b56fbfbfabba73f03df67c83d4497f86015baeebbe53c72bce42db332fe08a/work 0 0
[26 Jun 2018 7:57] Terje Røsten

Thanks for your report!

Can you explain why you what to upgrade MySQL server inside a running docker

To switch to new release you should start a new a image with wanted MySQL server
version inside.
[26 Jun 2018 8:02] Evgeniy Patlan
I'm trying to update/remove mysql on the HOST machine.
Let me explain it in another words:
I have machine which is running mysql locally and on the same machine I have docker which is also running mysql.

So while updating/removing locally installed mysql the issue appeared
[26 Jun 2018 8:12] Terje Røsten
Sorry, now I understand what you.

MySQL deb packaging scripts in host get confused by other mysqld running inside
docker on the same machine, this is due too simple logic to count mysqlds:

 ps -ef | grep "/usr/sbin/mysqld"  | wc -l
[26 Jun 2018 8:18] Evgeniy Patlan
Yes I understand this situation.
That's why I've submitted bug report.
There are several ways to proceed:
- use Debian's start-stop-daemon infrastructure
- detect if it is docker: for example
   The most reliable way is to check /proc/${pid}/cgroup. It will tell you the control groups of the init process, and when you are not in a container, that will be / for all hierarchies.

On the first glance the easiest way is to check cgroup and exclude process if it is running in docker or in lxc.
[26 Jun 2018 8:19] Terje Røsten
At first clance it seems like using start-stop-daemon infrastructure is the best way forward.

Thanks again for you report and suggestions!
[26 Jun 2018 8:21] Terje Røsten
Might be using cgroup is better, as least using old school ps and wc is not the way forward :-)
[10 Jul 2018 7:35] Lars Tangvald
I don't think we actually need these checks at all for an upgrade.

It is entirely valid for a debian|ubuntu user to have disabled the service
(so all starting|stopping of the service needs to be manual), in which case
an upgrade should be able to complete without stopping the old server process
or starting a new one.

We'll go through these scripts and update them for this scenario (we'll
probably still want some check on this for a package purge, at least).
[7 May 17:58] Paul Dubois
Posted by developer:
Fixed in 8.0.15.

If MySQL was running on the host system and within Docker, it was not
possible to update or remove MySQL on the host system.