日韩性视频-久久久蜜桃-www中文字幕-在线中文字幕av-亚洲欧美一区二区三区四区-撸久久-香蕉视频一区-久久无码精品丰满人妻-国产高潮av-激情福利社-日韩av网址大全-国产精品久久999-日本五十路在线-性欧美在线-久久99精品波多结衣一区-男女午夜免费视频-黑人极品ⅴideos精品欧美棵-人人妻人人澡人人爽精品欧美一区-日韩一区在线看-欧美a级在线免费观看

歡迎訪問 生活随笔!

生活随笔

當(dāng)前位置: 首頁 > 运维知识 > 数据库 >内容正文

数据库

mysql容器操作_如何使用运行MySQL构建Docker容器?

發(fā)布時(shí)間:2024/4/20 数据库 39 豆豆
生活随笔 收集整理的這篇文章主要介紹了 mysql容器操作_如何使用运行MySQL构建Docker容器? 小編覺得挺不錯(cuò)的,現(xiàn)在分享給大家,幫大家做個(gè)參考.

我的目標(biāo)是擁有一個(gè)具有運(yùn)行MySQL服務(wù)的docker容器.所以每當(dāng)我啟動(dòng)容器時(shí),數(shù)據(jù)庫都處于初始狀態(tài)并且MySQL正在運(yùn)行.

幾乎一切都很好但是當(dāng)我啟動(dòng)容器時(shí)MySQL服務(wù)沒有運(yùn)行.每次在控制臺(tái)中我都必須像這樣啟動(dòng)它:service mysql start.

以下是我構(gòu)建和運(yùn)行容器的步驟:

$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的內(nèi)容:

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 " 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

運(yùn)行我的容器后,如何更改我的Dockerfile以運(yùn)行MySQL服務(wù)?

總結(jié)

以上是生活随笔為你收集整理的mysql容器操作_如何使用运行MySQL构建Docker容器?的全部內(nèi)容,希望文章能夠幫你解決所遇到的問題。

如果覺得生活随笔網(wǎng)站內(nèi)容還不錯(cuò),歡迎將生活随笔推薦給好友。