简体   繁体   中英

Docker container dies after starting mysql server

I'm trying to build a sql docker container from ubuntu base. I build the image and run it. And am able to confirm that it's running, however it dies right away. How would I keep it alive?

Docker File

FROM ubuntu

RUN apt-get update && \
    apt-get install -y mysql-server
COPY run.sh /sbin/run.sh
COPY createDBTable.sql /
RUN chmod 755 /sbin/run.sh
CMD ["./sbin/run.sh"]

run.sh

#!/bin/sh
service mysql start
cat createDBTable.sql | mysql -u root
echo "show databases" | mysql -u root

Output of docker run

 * Starting MySQL database server mysqld
   ...done.
Database
information_schema
<new table>
mysql
performance_schema
sys

I created a docker container using the dockerfile mentioned above. Instead of running it in background using -d flag I used -it to start it in interactive mode. After some time the container stopped with the following error-

ERROR 2002 (HY000): Can't connect to local MySQL server through socket '/var/run/mysqld/mysqld.sock' (2)

You can try out various approaches to get rid of the above error using Google.

If there is something wrong with the container, you cannot keep it alive. What I would recommend will be to run the following:

docker logs mssql_container_name


replace "mssql_container_name" with the name of the container. If you didn't get the name, type: docker ps -a and get the name there. If you want you can post the answer to the docker logs here and maybe we can help you. But this is how you find out what happened to a container.

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