Guest User

Dockerfile (Xenial + Postgres)

a guest
Jul 27th, 2017
1,413
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 8.49 KB | None | 0 0
  1. # Building my own Docker image modeled after Heroku's production environment.
  2. # Started: 2017-07-25 based on a previous similar image that relies on MySQL instead.
  3. # WOULDDO:
  4. # • Set up user account so as to NOT run the image as root. e.g.: for Composer.
  5. # • Figure a way to log in to Heroku, but without commiting the logins to the image itself. e.g.: add config file via docker-compose.
  6.  
  7.  
  8.  
  9. ##
  10. # INSTALL MY STACK: LINUX + APACHE + POSTGRES + PHP + pseudo-email + supervisor
  11. ##
  12.  
  13. # 16.04 = Xenial
  14. FROM ubuntu:16.04
  15.  
  16.  
  17. # Avoid Dialog and other interactive features not suited to Dockerfiles
  18. ENV DEBIAN_FRONTEND noninteractive
  19.  
  20. # Update and configure packages
  21. # Installing apt-utils to avoid `debconf: delaying package configuration, since apt-utils is not installed` warning when installing programs (except for `apt-utils` itself.)
  22. RUN apt-get update
  23. RUN apt-get install -y --no-install-recommends apt-utils
  24.  
  25. # Set the timezone
  26. RUN apt-get install -y tzdata
  27. RUN echo "Europe/London" > /etc/timezone
  28. RUN dpkg-reconfigure -f noninteractive tzdata
  29. RUN ln -sf /usr/share/zoneinfo/Europe/Paris /etc/localtime
  30.  
  31.  
  32.  
  33. # Install Apache httpd
  34. # Note: remember Ubuntu uses `/etc/apache2/sites-available/` and `/etc/apache2/sites-enabled/` for vhosts.
  35. # e.g.: we may want to alias the latter to the former to enable all vhosts. See my notes in `Docker.md`.
  36. RUN apt-get install -y apache2
  37. RUN ln -s /etc/apache2/mods-available/rewrite.load /etc/apache2/mods-enabled/rewrite.load
  38.  
  39.  
  40.  
  41. # Install Postgres
  42. # Should I install `postgresql-contrib` too? suffixed -9.6?
  43. RUN apt-get install -y software-properties-common
  44. RUN add-apt-repository -y "deb http://apt.postgresql.org/pub/repos/apt/ xenial-pgdg main"
  45. RUN apt-get install -y wget
  46. RUN wget --quiet -O - https://www.postgresql.org/media/keys/ACCC4CF8.asc | apt-key add
  47. RUN apt-get update
  48. RUN apt-get install -y postgresql-9.6
  49. ENV PATH="${PATH}:/usr/lib/postgresql/9.6/bin"
  50.  
  51.  
  52.  
  53. # Install PHP 5.6.30
  54. # Note the use of ppa:ondrej/php to install older PHP 5.6 on newer Ubuntu 16.04 -- until we move to PHP 7.
  55. # It's never clear to me where to see the list of available packages for `ppa:ondrej/php`.
  56. # See https://askubuntu.com/a/756186/441757 and https://github.com/oerdnj/deb.sury.org/issues/56#issuecomment-230329082
  57. # Note: I wanted to instal PHP-FPM. Doable with the below commands (just use `-fpm` prefix) but did not manage to get it to work.
  58. RUN apt-get purge `dpkg -l | grep php| awk '{print $2}' |tr "\n" " "`
  59. RUN apt-get install -y software-properties-common
  60. RUN apt-get install -y language-pack-en-base
  61. RUN DEBIAN_FRONTEND=noninteractive LC_ALL=en_US.UTF-8 add-apt-repository -y ppa:ondrej/php
  62. RUN apt-get update
  63.  
  64. # Install PHP extensions
  65. # TO BE CLARIFIED: php5.6-mbstring php5.6-mcrypt php5.6-mysql php5.6-xml -- do I need them? what for?
  66. # XHProf: php-pear php5-dev php5-mcrypt -- note only `php-pear` available from `ppa:ondrej/php`
  67. RUN apt-get install -y --allow-unauthenticated php5.6
  68. RUN apt-get install -y --allow-unauthenticated php5.6-mbstring php5.6-mcrypt php5.6-mysql php5.6-xml php5.6-dev php5.6-curl php5.6-zip php5.6-pgsql
  69. RUN apt-get install -y --allow-unauthenticated php-pear
  70.  
  71.  
  72.  
  73. # Install supervisor
  74. # (We add its config file much later, as it depends on the other installed programs and is likely to change.
  75. # This way, we spare ourselves reinstalling things that didn't change when building the image.)
  76. RUN apt-get install -y supervisor
  77.  
  78.  
  79.  
  80. # Install mhsendmail · “sendmail replacement which forwards mail to an SMTP server”
  81. # Requires go and git.
  82. # Note: we're aliasing sendmail to call mhsendmail. (Fine for a development platform, not so for a production platform.)
  83. # Alternative, e.g.: config php.ini to use it directly. Why not if/when we have one php.ini per environment.
  84. # `/usr/sbin/sendmail` is the default `sendmail_path` in php.ini (hence preferable to a `/usr/local/bin/sendmail` alias.)
  85. RUN apt-get install -y git
  86. RUN apt-get install -y wget
  87. RUN wget https://storage.googleapis.com/golang/go1.8.1.linux-amd64.tar.gz
  88. RUN sha256sum go1.8.1.linux-amd64.tar.gz
  89. RUN tar -C /usr/local -xzf go1.8.1.linux-amd64.tar.gz
  90. ENV PATH="${PATH}:/usr/local/go/bin"
  91. RUN mkdir -p /root/gocode \
  92. && export GOPATH=/root/gocode \
  93. && go get github.com/mailhog/mhsendmail \
  94. && mv /root/gocode/bin/mhsendmail /usr/local/bin \
  95. && rm -rf /root/gocode
  96. RUN ln -s /usr/local/bin/mhsendmail /usr/sbin/sendmail
  97.  
  98. # Install MailHog · “email testing tool for developers”, i.e.: fake SMTP server for receiving my own outgoing mail.
  99. # Requires go and git.
  100. RUN mkdir -p /root/gocode \
  101. && export GOPATH=/root/gocode \
  102. && go get github.com/mailhog/MailHog \
  103. && mv /root/gocode/bin/MailHog /usr/local/bin \
  104. && rm -rf /root/gocode
  105.  
  106.  
  107.  
  108.  
  109.  
  110. ##
  111. # INSTALL MORE DEV SOFTWARE
  112. ##
  113.  
  114.  
  115. # Install Composer
  116. # See https://getcomposer.org/download/ for latest version
  117. RUN php -r "copy('https://getcomposer.org/installer', 'composer-setup.php');"
  118. RUN php -r "if (hash_file('SHA384', 'composer-setup.php') === '669656bab3166a7aff8a7506b8cb2d1c292f042046c5a994c43155c0be6190fa0355160742ab2e1c88d40d5be660b410') { echo 'Installer verified'; } else { echo 'Installer corrupt'; unlink('composer-setup.php'); } echo PHP_EOL;"
  119. RUN php composer-setup.php
  120. RUN php -r "unlink('composer-setup.php');"
  121. RUN mv composer.phar /usr/local/bin/composer
  122.  
  123.  
  124.  
  125. # Install PHPUnit 5.7 (i.e.: for PHP 5.6)
  126. # Alternative: do so from Composer.
  127. RUN apt-get install -y wget
  128. RUN wget https://phar.phpunit.de/phpunit-5.7.phar
  129. RUN chmod +x phpunit-5.7.phar
  130. RUN mv phpunit-5.7.phar /usr/local/bin/phpunit
  131. RUN phpunit --version
  132.  
  133.  
  134.  
  135. # Install BlackFire
  136. # See https://blackfire.io/docs/up-and-running/installation
  137. # CAREFUL! Personal LOGINS in here! (In the config files.)
  138. # WOULDDO: move those logins to environment variables.
  139. # For errors, check:
  140. # /etc/init.d/blackfire-agent status
  141. # Logs: `/var/log/blackfire/` and `/tmp/blackfire.log`
  142. # Let's disable it for now. I'm not using it.
  143. # RUN wget -O - https://packagecloud.io/gpg.key | apt-key add -
  144. # RUN echo "deb http://packages.blackfire.io/debian any main" | tee /etc/apt/sources.list.d/blackfire.list
  145. # RUN apt-get update
  146. # RUN apt-get install blackfire-agent
  147. # ADD config/agent /etc/blackfire/agent
  148. # #RUN blackfire-agent -register --server-id=b28430c8-380f-4117-9637-2a76cd5ddfdd --server-token=7dff98b95e60bb3c142f2752c6a536872e0a63a2d3d03df1c3d74a371a086e2e
  149. # #RUN apt-get install blackfire-agent
  150. # #RUN blackfire config --client-id="3a1dd7f3-bf2d-4a67-a34f-23f71f62d0c6" --client-token="df395989949be7174279da6ffb6c3314854ae41d8448ae8f15e73f081d38aea4" # does not work
  151. # ADD config/blackfire.ini /root/.blackfire.ini
  152. # RUN apt-get install blackfire-php
  153. # #RUN apache2ctl restart
  154.  
  155.  
  156.  
  157. # Install Heroku CLI
  158. # Last because the install process changes frequently.
  159. # WOULDDO: maybe install PHP Buildpack too?
  160. RUN echo "FORCE HEROKU CLI UPDATE" # Need to rebuild the image once in a while when a new version of the Heroku CLI is available. NEXT TIME: may want to move it to end of file.
  161. RUN wget -qO- https://cli-assets.heroku.com/install-ubuntu.sh | sh
  162.  
  163.  
  164.  
  165.  
  166.  
  167. ##
  168. # TEMPORARY OR NON-CRITICAL
  169. ##
  170.  
  171. # Re-install MySQL (MariaDB) to let us convert from MySQL to Postgres
  172. RUN apt-get update # without it (depsite an earlier identical command), it fails to grab `0.90ubuntu0.5` (not found) instead of fetching `0.90ubuntu0.6`.
  173. RUN apt-get install -y mariadb-server mariadb-client
  174.  
  175. # Pgloader
  176. RUN apt-get install -y pgloader
  177.  
  178. # Test
  179. # RUN chown -R postgres:postgres /var/lib/postgresql/9.6/main/
  180. # RUN chmod -R u+rwx,g-rwx,o-rwx /var/lib/postgresql/9.6/main/
  181.  
  182.  
  183.  
  184.  
  185. # PORTS TO EXPOSE
  186. # 22: SSH
  187. # 80: TCP, HTTP
  188. # 8025: MailHog UI (web)
  189. # 3306: MySQL to connect via a client (e.g.: Sequel Pro) -- but failed to get this to work.
  190. # 5432: Postgres -- but I did not need to export the MySQL port for things to work… So it's confusing why and whether I would need it here.
  191. EXPOSE 22 80 8025 3306 5432
  192.  
  193.  
  194.  
  195. # Entry point for when the image starts
  196. ADD supervisord.conf /etc/
  197. CMD ["/usr/bin/supervisord"]
  198.  
  199.  
  200.  
  201.  
  202.  
  203. ## MEMO.
  204. #
  205. # BUILD THE IMAGE LIKE SO:
  206. # cd /Users/fabien/Dropbox/DEV/Docker/images/img-fab-ubuntu-postgres
  207. # docker build -t fab/ubuntu-postgres .
  208. # Use `--no-cache` if needed.
  209. #
  210. # START THE IMAGE VIA DOCKER TO CHECK IT OUT:
  211. # docker run --name myubuntu -dit fab/ubuntu-postgres
  212. # docker exec -it myubuntu /bin/bash
  213. #
  214. # Besides installing programs here, remember to set them up to run inside of `supervisord.conf`!
  215. # Check they're actually running with `service --status-all`
  216. #
  217. # STATS: 2017-06-07, 12 min to build.
Advertisement
Add Comment
Please, Sign In to add comment