如何使用运行MySQL构建Docker容器?

如何使用运行MySQL构建Docker容器?,第1张

概述我的目标是拥有一个具有运行MySQL服务的docker容器.所以每当我启动容器时,数据库都处于初始状态并且MySQL正在运行.几乎一切都很好但是当我启动容器时MySQL服务没有运行.每次在控制台中我都必须像这样启动它:service mysql start.以下是我构建和运行容器的步骤:$docker build -t executer:mysql . Se

我的目标是拥有一个具有运行MySQL服务的docker容器.所以每当我启动容器时,数据库都处于初始状态并且MysqL正在运行.
几乎一切都很好但是当我启动容器时MysqL服务没有运行.每次在控制台中我都必须像这样启动它:service MysqL start.
以下是我构建和运行容器的步骤:

$docker build -t executer:MysqL .Sending build context to Docker daemon 15.87 kBSending build context to Docker daemon Step 0 : FROM debian:wheezy## ... Many steps without error#Step 17 : RUN MysqL_install_db --user=MysqL --basedir=/usr/ --ldata=/var/lib/MysqL/ ---> Using cache ---> 1c71bf4524f0Step 18 : RUN service MysqL start ---> Running in b4643765b79b......MysqL Community Server 5.6.24 is started. ---> ac26b749a3c0Removing intermediate container b4643765b79bSuccessfully built ac26b749a3c0 $docker run --rm -it executer:MysqL /bin/bashroot@1d9208c19af0:/# MysqLERROR 2002 (HY000): Cant connect to local MysqL server through socket '/var/run/MysqLd/MysqLd.sock' (111)root@1d9208c19af0:/# service MysqL startNo directory,logging in with HOME=/......[info] MysqL Community Server 5.6.24 is started.root@1d9208c19af0:/# MysqLWelcome to the MysqL monitor.  Commands end with ; or \g.Your MysqL connection ID is 1Server version: 5.6.24 MysqL Community Server (GPL)copyright (c) 2000,2015,Oracle and/or its affiliates. All rights reserved.Oracle is a registered Trademark of Oracle Corporation and/or itsaffiliates. Other names may be Trademarks of their respectiveowners.Type 'help;' or '\h' for help. Type '\c' to clear the current input statement.MysqL> 

这是Dockerfile的内容:

FROM debian:wheezy# add our user and group first to make sure their IDs get assigned consistently,regardless of whatever dependencIEs get addedRUN groupadd -r MysqL && useradd -r -g MysqL MysqL# Fatal error: please install the following Perl modules before executing /usr/local/MysqL/scripts/MysqL_install_db:# file::Basename# file::copy# Sys::Hostname# Data::DumperRUN apt-get update && apt-get install -y perl --no-install-recommends && rm -rf /var/lib/apt/Lists/*# gpg: key 5072E1F5: public key "MysqL Release Engineering 

运行我的容器后,如何更改我的Dockerfile以运行MysqL服务?最佳答案我试过你的设置

见https://github.com/BITPlan/docker-stackoverflowanswers/tree/master/33299303

我先得到了

E: Version '5.6.24*' for 'MysqL-server' was not found

这与你的问题无关,但需要修复.
所以我注释掉你的大部分Dockerfile并添加:

RUN apt-get install MysqL-server-5.5

这给了:
    E:无法找到包MysqL-server-5.5

这是特定于发行版的,所以我将FROM行更改为

FROM ubuntu:14.04

我更熟悉

然后我修改了Dockerfile来改变

RUN service MysqL start

CMD service MysqL start

正如michaelbahr的评论中所提到的那样

./run 

root@96ff34b4e0c0:/# service --status-all 2>&1 | grep MysqL

结果显示:

[ ? ]  MysqL

你在那里 – MysqL运行.
您可能希望相应地修复Dockerfile. 总结

以上是内存溢出为你收集整理的如何使用运行MySQL构建Docker容器?全部内容,希望文章能够帮你解决如何使用运行MySQL构建Docker容器?所遇到的程序开发问题。

如果觉得内存溢出网站内容还不错,欢迎将内存溢出网站推荐给程序员好友。

欢迎分享,转载请注明来源:内存溢出

原文地址: http://outofmemory.cn/sjk/1168303.html

(0)
打赏 微信扫一扫 微信扫一扫 支付宝扫一扫 支付宝扫一扫
上一篇 2022-06-01
下一篇 2022-06-01

发表评论

登录后才能评论

评论列表(0条)