简体   繁体   中英

mysqld runs while I'm running MySQL in a Docker container

I am running the MySQL service on a docker container, but I found something weird, I found mysqld is running on my host. anyone knows how that can happen? Because in my opinion, I think that Docker container and a PC host is really disconnected,

but why mysqld running while I am running MySQL in a Docker container?

This is how containers, more specifically namespaces work. The mysqld is running in its own process namespace and you can as many mysqld processes as physically possible without interfering with the others due to other namespaces (filesystem, network, pid etc)

Namespaces are what allows isolation of the container (and its process) from the host system and also from other containers. This is what allows the containers to behave as true virtual environments. There are 6 different namespaces:

(1) PID Namespace: This allows you to run processes inside a container with a pid that is independent of the pid inside the host or any other container on that host (or any host for that matter). Which is why you can have PID 1 inside every container and again a PID on the host.

(2) NET Namespace: Allows you to have a totally independent IP stack, ie, IP address and exposed ports inside each container.

(3) Filesystem / MNT Namespace: You can have an independent filesystem (the / (root) filesystem) and a scoped view of the mounts from the host.

(4) UTS Namespace: Allows to assign independent hostname & domain name, basically anything needed for system identification.

(5) IPC Namespace: For independent & isolated inter-process communications à la SysV calls / message queues inside your containers.

(6) User Namespace: Root in your container is not necessarily root inside your host. You can map any user inside the container to any user on the host.

If you pull up the pid of the mysqld process, you'll see it has a different pid than the one inside the container (typically 1), but there are the same process.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM