自定义Docker MySQL构建将无法运行

时间:2016-03-14 10:25:37

标签: mysql docker docker-compose dockerfile

我正在尝试编写自定义Dockerfile来设置Mysql 5.7。

作为其中的一部分,我也想设置s3备份。

但是当我尝试运行/创建docker实例时,它失败了

这是Dockerfile:

# Start with a base mysql:5.6 image
FROM mysql:5.7

MAINTAINER Ikenna N. Okpala <me@ikennaokpala.com>

USER root
# RUN locale-gen
ENV DEBIAN_FRONTEND noninteractive
ENV LANG en_US.UTF-8
ENV LANGUAGE en_US.en
ENV LC_ALL en_US.UTF-8
ENV PS_NGX_EXTRA_FLAGS --with-cc=/usr/bin/gcc --with-ld-opt=-static-libstdc++


# Add all base dependencies
RUN apt-get update -y

RUN apt-get install -y build-essential checkinstall
RUN apt-get install -y vim curl wget unzip
RUN apt-get install -y libfuse-dev libcurl4-openssl-dev mime-support automake libtool python-docutils libreadline-dev
RUN apt-get install -y pkg-config libssl-dev
RUN apt-get install -y git-core
RUN apt-get install -y man cron
RUN apt-get install -y libgmp-dev
RUN apt-get install -y zlib1g-dev
RUN apt-get install -y libxslt-dev
RUN apt-get install -y libxml2-dev
RUN apt-get install -y libpcre3 libpcre3-dev
RUN apt-get install -y freetds-dev
# RUN apt-get install -y openjdk-7-jdk
RUN apt-get install -y software-properties-common

RUN mkdir -p /mnt/s3b

RUN sed -i -e"s/^bind-address\s*=\s*127.0.0.1/bind-address = 0.0.0.0/" /etc/mysql/my.cnf

RUN cd ~/
RUN /bin/bash -l -c "wget https://github.com/s3fs-fuse/s3fs-fuse/archive/master.zip"
RUN unzip master.zip
RUN cd s3fs-fuse-master/ && ./autogen.sh && ./configure --prefix=/usr --with-openssl && make && make install

ADD templates/setup.sh /root/setup.sh
RUN chmod +x /root/setup.sh

ADD templates/backup-cron /etc/cron.d/backup-cron
RUN chmod 0644 /etc/cron.d/backup-cron
RUN cron
# RUN chmod +x /root/backup-cron

EXPOSE 3306

CMD ["/bin/bash", "-l", "-c", "/root/setup.sh"]

这是setup.sh文件

#!/bin/bash
export MYSQL_HOST_IP=`awk 'NR==1 {print $1}' /etc/hosts`

set -e
set -x

# NOW=$(date +"%Y-%m-%d-%H%M")

# DUMP_FILE="/dumps/dump.sql"

echo $AWS_S3 >> ~/.passwd-s3fs && cp ~/.passwd-s3fs /etc/passwd-s3fs

chmod 600 ~/.passwd-s3fs
chmod 640 /etc/passwd-s3fs

mysql -h$MYSQL_HOST_IP -uroot -p$MYSQL_ROOT_PASSWORD -e "DROP DATABASE IF EXISTS $MYSQL_DATABASE; CREATE USER '$MYSQL_USER'@'localhost' IDENTIFIED BY '$MYSQL_PASSWORD'; CREATE DATABASE $MYSQL_DATABASE; GRANT ALL ON $MYSQL_DATABASE.* TO '$MYSQL_USER'@'localhost'; FLUSH PRIVILEGES;"

这是docker run命令:

docker run --name=mysql-s3 --env MYSQL_ROOT_PASSWORD=${MYSQL_ROOT_PASSWORD} --env MYSQL_USER=${MYSQL_USER} --env MYSQL_PASSWORD=${MYSQL_PASSWORD} --env MYSQL_DATABASE=${MYSQL_DATABASE} --env AWS_S3=${AWS_S3} --detach --publish 3306:3306 --volume=/vagrant/scripts/dumps/:/dumps/ --cap-add mknod --cap-add sys_admin --device=/dev/fuse --privileged mysql-s3

1 个答案:

答案 0 :(得分:2)

这种方法使用fuse并修改基本mysql容器似乎太复杂了。我建议您只需坚持使用基本MYSQL并编写一个脚本,该脚本在一个单独的容器中运行,该容器对文本文件执行MYSQL转储,然后使用AWS CLI将该文本文件复制到S3。