docker制作mysql-client的镜像(基于centos)

由于我的程序需要往mysql数据库中存数据,用到了libmysqlclient.so,所以把我的程序放到docker中运行的时候,需要在docker镜像中包含libmysqlclient.so。

网上有基于alpine的mysql-client。感觉不行。我们还是用centos的镜像感觉保险一点。

1.build.sh

从mysql的官网下载mysql相关rpm到本地

#!/bin/bash


wget https://repo.mysql.com/yum/mysql-5.7-community/el/7/x86_64/mysql-community-common-5.7.27-1.el7.x86_64.rpm
wget https://repo.mysql.com/yum/mysql-5.7-community/el/7/x86_64/mysql-community-libs-5.7.27-1.el7.x86_64.rpm
wget https://repo.mysql.com/yum/mysql-5.7-community/el/7/x86_64/mysql-community-client-5.7.27-1.el7.x86_64.rpm



docker build -t mysql-client  .

 

Dockerfile



FROM centos:7

MAINTAINER along <aaaa@gmail.com>

#ADD /mysql-community-common-5.7.27-1.el7.x86_64.rpm  /mysql-community-common-5.7.27-1.el7.x86_64.rpm
#ADD /mysql-community-libs-5.7.27-1.el7.x86_64.rpm 	 /mysql-community-libs-5.7.27-1.el7.x86_64.rpm
#ADD /mysql-community-client-5.7.27-1.el7.x86_64.rpm  /mysql-community-client-5.7.27-1.el7.x86_64.rpm

ARG MYSQL_1=/mysql-community-common-5.7.27-1.el7.x86_64.rpm
ARG MYSQL_2=/mysql-community-libs-5.7.27-1.el7.x86_64.rpm
ARG MYSQL_3=/mysql-community-client-5.7.27-1.el7.x86_64.rpm

ADD $MYSQL_1 $MYSQL_1
ADD $MYSQL_2 $MYSQL_2
ADD $MYSQL_3 $MYSQL_3
# -----------------------------------------------------------------------------
# MySQL client
# -----------------------------------------------------------------------------
RUN	   yum install -y $MYSQL_1 \
	&& yum install -y $MYSQL_2 \
	&& yum install -y $MYSQL_3 \
	&& rm -rf $MYSQL_1 \
	&& rm -rf $MYSQL_2 \
	&& rm -rf $MYSQL_3 \
	&& rm -rf /var/cache/yum/* \

 

 

reference:

https://github.com/arey/mysql-client/blob/master/Dockerfile

https://stackoverflow.com/questions/30082674/how-to-install-a-local-rpm-file-when-building-docker-instance/30083919

 

 

©️2020 CSDN 皮肤主题: 1024 设计师:上身试试 返回首页