It's possible, but it's an anti-pattern.
By jamming multiple unrelated things into a single image, you end up with several problems:
- You have to rebuild the image and redeploy your containers every time you want to upgrade either mysql or wordpress. When you have separate images, you can deploy a new version of wordpress without having to restart your database.
- You can't take advantage of the upstream-maintained official images (like the official
mysql
and wordpress
images).
- You will invariably hide service errors from Docker. With
mysql
and wordpress
running in separate images, the Docker daemon knows when something crashes and can restart it (given an appropriate restart policy), but this isn't possible if you've got something running in the background.
- You have dramatically reduced your flexibility: using separate images, you can replace the
mysql
image with a Galera cluster, or you can run multiple Wordpress containers for load balancing purposes all pointing at the same backend database. If you bundle everything into a single image this becomes less convenient.
That said, your CMD
or ENTRYPOINT
scripts can do whatever you want: if you want to start something in the background before starting the final foreground process, you can do that! If you want to start up a process supervisor of some sort, you can do that too!
But I think you're better off utilizing the official images as much as possible, and using docker-compose (or another higher-level orchestrator) to compose applications from multiple parts.