- centos7基礎鏡像Dockerfile來構建mysql鏡像可能會有問題,在Docker hub上構建失敗:
Build failed: The command '/bin/sh -c /etc/init.d/mysqld start && mysql -e "grant all privileges on *.* to 'root'@'%' identified by '123456' WITH GRANT OPTION ;"&& mysql -e "grant all privileges on *.* to 'root'@'localhost' identified by '123456' WITH GRANT OPTION ;"&& mysql -u root -p123456 -e "show databases;"' returned a non-zero code: 127
使用的Dockerfile如下:
# 基於centos7基礎鏡像
FROM centos:7
WORKDIR /home
# 使用yum的方式安裝mysql;
RUN yum install -y mysql-server mysql
# 安裝完成以後,執行以下命令。配置用戶名密碼相關信息;
RUN /etc/init.d/mysqld start &&\
mysql -e "grant all privileges on *.* to 'root'@'%' identified by '123456' WITH GRANT OPTION ;" && \
mysql -e "grant all privileges on *.* to 'root'@'localhost' identified by '123456' WITH GRANT OPTION ;" && \
mysql -u root -p123456 -e "show databases;" && \
ln -snf /usr/share/zoneinfo/$TZ /etc/localtime && echo $TZ > /etc/timezone && \
yum clean all
# 設置環境變量
ENV TZ Asia/Shanghai
# 鏡像暴露3306端口;
EXPOSE 3306
# 容器啓動後執行以下命令,啓動mysql;
CMD ["/usr/bin/mysqld_safe"]
- 同樣centos7基礎鏡像來構建redis鏡像也會有同樣的問題:
Build failed: The command '/bin/sh -c make && make install' returned a non-zero code: 127
使用的Dockerfile如下:
# 基於centos7基礎鏡像
FROM centos:7
WORKDIR /home
# 安裝redis
RUN yum install -y wget gcc && \
rpm --rebuilddb && \
yum install -y tar && \
tar -xvzf redis-stable.tar.gz && \
mv redis-stable/ redis && \
rm -f redis-stable.tar.gz && \
ln -snf /usr/share/zoneinfo/$TZ /etc/localtime && echo $TZ > /etc/timezone && \
yum clean all
WORKDIR /home/redis
RUN make && make install
# 設置時區的環境變量
ENV TZ Asia/Shanghai
# 把工作目錄切換到/home下
WORKDIR /home
# 開放端口
EXPOSE 6379
# 啓動容器後執行以下命令
ENTRYPOINT redis-server /home/redis/redis.conf
CMD ["redis-server"]
- 推薦使用centos6基礎鏡像,而不用centos6.7等,因爲centos6會有不斷的更新,更加穩定。
- 不推薦使用centos7,會有很多坑。所以就選擇centos6好了。