2018年12月14日

利用 dockerfile 建立自己的 image

因為用 export 或是 save 移到別台都會出現問題,又不方便每次都上 docker hub 拉,只好自己在每台上面建 image

1.為避免每次都要從外網拉檔案、先手動把mysql拉下來放到內網某台有提供http服務的機器上
2.進入容器內、把 entrypoint.sh 複製出來成 docker-entrypoint.sh
3.建立 Dockerfile
FROM ubuntu:trusty

RUN groupadd -r mysql && useradd -r -g mysql mysql

RUN apt-get update && \
apt-get install -y curl binutils

RUN gpg --keyserver pgp.mit.edu --recv-keys A4A9406876FCBD3C456770C88C718D3B5072E1F5

RUN locale-gen en_US.UTF-8 &&\
update-locale

ENV LANG en_US.UTF-8

ENV LANGUAGE en_US:en

ENV LC_ALL en_US.UTF-8

RUN curl -SL "http://192.168.1.1/mysql-5.1.73-linux-x86_64-glibc23.tar.gz" -o mysql.tar.gz && \
curl -SL "http://192.168.1.1/mysql-5.1.73-linux-x86_64-glibc23.tar.gz.asc" -o mysql.tar.gz.asc && \
gpg --verify mysql.tar.gz.asc && \
mkdir /usr/local/mysql && \
tar -xzf mysql.tar.gz -C /usr/local/mysql --strip-components=1 && \
rm mysql.tar.gz* && \
rm -rf /usr/local/mysql/mysql-test /usr/local/mysql/sql-bench && \
rm -rf /usr/local/mysql/bin/*-debug /usr/local/mysql/bin/*_embedded && \
find /usr/local/mysql -type f -name "*.a" -delete && \
{ find /usr/local/mysql -type f -executable -exec strip --strip-all '{}' + || true; } && \
apt-get purge -y --auto-remove binutils && \
rm -rf /var/lib/apt/lists/*

ENV PATH $PATH:/usr/local/mysql/bin:/usr/local/mysql/scripts

WORKDIR /usr/local/mysql

VOLUME /var/lib/mysql

COPY docker-entrypoint.sh /entrypoint.sh

ENTRYPOINT ["/entrypoint.sh"]

EXPOSE 3306

CMD ["mysqld", "--datadir=/var/lib/mysql", "--user=mysql"]


4.#docker build -t="mysql-5.1.73" .

0 意見:

張貼留言