简体   繁体   English

启动mysql服务器后Docker容器死亡

[英]Docker container dies after starting mysql server

I'm trying to build a sql docker container from ubuntu base. 我正在尝试从ubuntu基础构建一个sql docker容器。 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 Docker文件

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 run.sh

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

Output of docker run 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. 我使用上面提到的dockerfile创建了一个docker容器。 Instead of running it in background using -d flag I used -it to start it in interactive mode. 我不是使用-d标志在后台运行它,而是使用-it在交互模式下启动它。 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. 您可以使用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. 用容器名称替换“ mssql_container_name”。 If you didn't get the name, type: docker ps -a and get the name there. 如果没有得到名称,请键入: docker ps -a并在那里获得名称。 If you want you can post the answer to the docker logs here and maybe we can help you. 如果您愿意,可以在此处将答案发布到docker日志中,也许我们可以为您提供帮助。 But this is how you find out what happened to a container. 但是,这是您找出容器发生了什么的方法。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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