我的目标是拥有一个具有运行MySQL服务的docker容器.所以每当我启动容器时,@R_301_457@都处于初始状态并且MysqL正在运行.
几乎一切都很好但是当我启动容器时MysqL服务没有运行.每次在控制台中我都必须像这样启动它:service MysqL start.
以下是我构建和运行容器的步骤:
$docker build -t executer:MysqL .
Sending build context to Docker daemon 15.87 kB
Sending 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
---> 1c71bf4524f0
Step 18 : RUN service MysqL start
---> Running in b4643765b79b
......
MysqL Community Server 5.6.24 is started.
---> ac26b749a3c0
Removing intermediate container b4643765b79b
Successfully built ac26b749a3c0
$docker run --rm -it executer:MysqL /bin/bash
root@1d9208c19af0:/# MysqL
ERROR 2002 (HY000): Cant connect to local MysqL server through socket '/var/run/MysqLd/MysqLd.sock' (111)
root@1d9208c19af0:/# service MysqL start
No directory,logging in with HOME=/
......
[info] MysqL Community Server 5.6.24 is started.
root@1d9208c19af0:/# MysqL
Welcome to the MysqL monitor. Commands end with ; or \g.
Your MysqL connection id is 1
Server 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 its
affiliates. Other names may be trademarks of their respective
owners.
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 added
RUN 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::Dumper
RUN 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 <MysqL-build@oss.oracle.com>" imported
RUN apt-key adv --keyserver pool.sks-keyservers.net --recv-keys A4A9406876FCBD3C456770C88C718D3B5072E1F5
ENV MysqL_MAJOR 5.6
ENV MysqL_VERSION 5.6.24
RUN echo "deb http://repo.MysqL.com/apt/debian/ wheezy MysqL-${MysqL_MAJOR}" > /etc/apt/sources.list.d/MysqL.list
# the "/var/lib/MysqL" stuff here is because the MysqL-server postinst doesn't have an explicit way to disable the MysqL_install_db codepath besides having a database already "configured" (ie,stuff in /var/lib/MysqL/MysqL)
# also,we set debconf keys to make APT a little quieter
RUN { \
echo MysqL-community-server MysqL-community-server/data-dir select ''; \
echo MysqL-community-server MysqL-community-server/root-pass password ''; \
echo MysqL-community-server MysqL-community-server/re-root-pass password ''; \
echo MysqL-community-server MysqL-community-server/remove-test-db select false; \
} | debconf-set-selections \
&& apt-get update && apt-get install -y MysqL-server="${MysqL_VERSION}"* && rm -rf /var/lib/apt/lists/* \
&& rm -rf /var/lib/MysqL && mkdir -p /var/lib/MysqL
RUN apt-get update && apt-get install -y procps
# comment out a few problematic configuration values
RUN sed -Ei 's/^(bind-address|log)/#&/' /etc/MysqL/my.cnf
# VOLUME /var/lib/MysqL
# Install database
ADD ./database.sql /var/db/database.sql
# Set Standard settings
ENV user student
ENV password secret
ENV url file:/var/db/database.sql
ENV right READ
# Install starting script
ADD ./start-database.sh /usr/local/bin/start-database.sh
RUN chmod +x /usr/local/bin/start-database.sh
#EXPOSE 3306
RUN MysqL_install_db --user=MysqL --basedir=/usr/ --ldata=/var/lib/MysqL/
RUN service MysqL start
运行我的容器后,如何更改我的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.