Successfully reported this slideshow.
We use your LinkedIn profile and activity data to personalize ads and to show you more relevant ads. You can change your ad preferences anytime.

混用 Ansible 建置 Docker image

322 views

Published on

Intro the mix mode of Dockerfile and Ansible.

If you are interested, you can see the "28. 怎麼混用 Ansible 建置 Docker image?" [1].

PS: This is a lighting talk slide at "Docker Birthday #4 Celebration" [2].

----
[1]: http://ithelp.ithome.com.tw/articles/10187861
[2]: https://www.meetup.com/Docker-Taipei/events/237978710/

Published in: Technology
  • Be the first to comment

混用 Ansible 建置 Docker image

  1. 1. 混用 Ansible 建置 Docker Image Presented by chusiang Mar 19th, 2017 Docker.Taipei
  2. 2. Dockerfile 客製化 docker image 用的檔案
  3. 3. 簡單的 Dockerfile # This dockerfile uses the ubuntu image # VERSION 2 - EDITION 1 # Author: docker_user # Command format: Instruction [arguments / command] .. # 基本映像檔,必須是第一個指令 FROM ubuntu # 維護者: docker_user <docker_user at email.com> (@docker_user) MAINTAINER docker_user docker_user@email.com # 更新映像檔的指令 RUN echo "deb http://archive.ubuntu.com/ubuntu/ raring main universe" >> /etc/apt/sources.list RUN apt-get update && apt-get install -y nginx RUN echo "ndaemon off;" >> /etc/nginx/nginx.conf # 建立新容器時要執行的指令 CMD /usr/sbin/nginx 一般由基底映像檔資訊、維護者資訊、映像檔操作指令和容器 啟動指令四部分組成。 這裡用到了以下 4 個指令: ● FROM ● MAINTAINER ● RUN ● CMD 資料來源: ● 《Docker — 從入門到實踐­》正體中文版 | GitBook
  4. 4. 較複雜的 Dockerfile FROM ubuntu MAINTAINER imtnd RUN apt-get update -y && apt-get install -y apache2 php5 wget php5-mysql RUN wget -q http://sourceforge.net/projects/testlink/files/TestLink%201.9/TestLink%201. 9.14/testlink-1.9.14.tar.gz/download -O testlink-1.9.14.tar.gz && tar zxvf testlink-1.9.14.tar.gz && mv testlink-1.9.14 /var/www/html/testlink && rm testlink-1.9.14.tar.gz RUN echo "max_execution_time=3000" >> /etc/php5/apache2/php.ini && echo "session.gc_maxlifetime=60000" >> /etc/php5/apache2/php.ini ENV APACHE_RUN_USER www-data ENV APACHE_RUN_GROUP www-data ENV APACHE_LOG_DIR /var/log/apache2 ENV APACHE_PID_FILE /var/run/apache2.pid 以 imtnd/testlink image 的 Dockerfile 為例。 ENV APACHE_RUN_DIR /var/run/apache2 ENV APACHE_LOCK_DIR /var/lock/apache2 RUN mkdir -p $APACHE_RUN_DIR $APACHE_LOCK_DIR $APACHE_LOG_DIR RUN mkdir -p /var/testlink/logs /var/testlink/upload_area RUN chmod 777 -R /var/www/html/testlink && chmod 777 -R /var/testlink/logs && chmod 777 -R /var/testlink/upload_area EXPOSE 80/tcp CMD ["/usr/sbin/apache2","-D", "FOREGROUND"]
  5. 5. 公司的 Dockerfile FROM ubuntu MAINTAINER imtnd RUN apt-get update -y && apt-get install -y apache2 php5 wget php5-mysql RUN wget -q http://sourceforge.net/projects/testlink/files/TestLink%201.9/TestLink%201.9.14/testlink-1.9.14.tar.gz/download -O testlink-1.9.14.tar.gz && tar zxvf testlink-1.9.14.tar.gz && mv testlink-1.9.14 /var/www/html/testlink && rm testlink-1.9.14.tar.gz RUN echo "max_execution_time=3000" >> /etc/php5/apache2/php.ini && echo "session.gc_maxlifetime=60000" >> /etc/php5/apache2/php.ini …... 絕對沒有那麼簡單!
  6. 6. Dockerfile + Ansible 把複雜的組態設定交給 Ansible 就對了!
  7. 7. 混用 Ansible 的 Dockerfile FROM williamyeh/ansible:ubuntu14.04-onbuild MAINTAINER Chu-Siang Lai <chusiang.lai@gmail.com> # fix policy-rc.d for Docker # @see http://www.monblocnotes.com/node/2057 # @see http://askubuntu.com/a/365912 RUN sed -i -e 's/exitss*101/exit 0/' /usr/sbin/policy-rc.d # init RUN sudo apt-get install -y curl git make ; git clone https://github.com/chusiang/testlink.ansible.role.git ; cd testlink.ansible.role ; make init ENV PLAYBOOK testlink.ansible.role/setup.yml RUN ansible-playbook-wrapper -vvv RUN cp run.sh / 以 chusiang/testlink image 的 Dockerfile 為例。 EXPOSE 80 443 VOLUME [ "/data" ] ENTRYPOINT [ "/run.sh" ]
  8. 8. https://github.com/chusiang/testlink.ansible.role
  9. 9. https://hub.docker.com/r/chusiang/testlink
  10. 10. https://hub.docker.com/r/chusiang/testlink/builds
  11. 11. 為什麼要混用 Ansible? 比 Shell Script 好維護 支援多種環境 (實體機、VM、Docker) Infrastructure as Code 可一份組態適用多個 OS 透過 Ansible 存取系統變數 不是每家公司都敢在 Productoin 跑 Docker
  12. 12. Reference 《Docker — 從入門到實踐­》正體中文版 | GitBook 28. 怎麼混用 Ansible 建置 Docker image? | iT 邦幫忙 從 Ansible 到 Docker:混血模式 | 軟體架構・絮語A Google Slides Themes UX Template | Free Google Slides Templates
  13. 13. 13 END

×