Stack Exchange network consists of 183 Q&A communities including Stack Overflow, the largest, most trusted online community for developers to learn, share their knowledge, and build their careers.
Try to run your telnet command without ansible and verify it's expecting exactly those 6 responses .. seems that expect is still awaiting for one of those inputs to be rendered until timeout.
Because RUN apt-get install .. will create an intermediate container , run commands then commit it to the final image. In your example, first you're starting MySQL server creating data then commiting to the final image but then running a second server with a new intermediate container and empty database.