Home > alpine-linux, DevOps, docker, docker-compose, nginx, php7 > Nginx+PHP7 on Alpine Linux as base Docker image

Nginx+PHP7 on Alpine Linux as base Docker image


It all started in a calm morning of 2nd June, with the smell of coffee and DevOps email newsletters…then suddenly when I was building my Docker image for Drupal 8 development I realized it was taking too damn long…

After I did a docker images and saw that my Apache2 + PHP image was weighting 195 MB I figured WTF?! It can’t be that big…and it only has a goddamn Apache + PHP in it…

After checking on other projects and discussing on the official IRC channel, I was convinced it’s time for a change…

Why Alpine Linux as base image

First of all, I don’t like Docker images full of useless crap! I am in control here, not the docker image, and if I want it at 20 kilos, I’m pretty sure I’m gonna pump that modafucka` to 20 kilos if I want…

When I saw that every image based from Ubuntu weights min. 190 MB, I decided to change direction to my old friend Alpine Linux. Me and Alpine know each other since they published they’re first stable release, but I was too scared back then to use it as Base image as it wasn’t so mature…

First step was RECON. During my development I found some interesting projects based from Alpine Linux, and I decided to build my server image of

  • NGINX
  • PHP 7
  • PHP 7 FPM
  • supervisord

For the Database I’ve chosen kiasaki/alpine-postgres/ as it was based from the official Alpine Linux postgres docker image, and it was using their environment variables. So it was easy.

Alpine Linux community

The Alpine Linux IRC community was awesome, I have to say I couldn’t have done it without them. There are very good and professional people out there, and everyone’s willing to help if you know how to ask…

I thought Alpine Linux didn’t have envsubst, a binary to substitute environment variables from bash scripts, but they’ve directed me to the right path:

(17:10:41) darkfader: dminca: you can open a package request for it
(17:10:49) darkfader: sounds like an easy to build package in that case
(17:10:52) kl3:  $ apk info --who-owns $(which envsubst)
(17:10:53) kl3: /usr/bin/envsubst is owned by gettext-0.19.7-r3
(17:10:56) darkfader: or
(17:10:59) darkfader: that :)
(17:11:23) dminca: awesome kl3 darkfader , thanks guys :)
(17:12:07) dminca: and how can I install it from other source?
(17:12:15) kl3: dminca: You're welcome.
(17:12:18) dminca: apk add ... ?
(17:13:03) kl3: gettext is in the main repo, just do 'apk add gettext'
(17:13:39) dminca: yay ! I got envsubst, thank you kl3 :D

Numbers and other data

Atm, this is the difference between

  1. A Docker image based from Ubuntu wily with Apache + PHP 5 + Drupal Console
    1. tagged as latest
  2. A Docker image based from Alpine Linux with Nginx + PHP 7 + PHP 7 FPM + supervisord
    1. tagged as alpine

Selection_005Selection_006

Wrap up

During the development, at the middle of the road I was thinking I wouldn’t make it. Nginx configuration files really pissed me off, but I calmed down after asking on #nginx IRC channel and reading a few Nginx docs (that btw can be found in the References section of the project) plus asking on serverfault.com.

I’ve learned the following from this journey:

  1. never give up!
  2. read the docs and try again
  3. keep the objective in mind so you won’t get lost from your path
  4. kindly ask the community to help, but only after step #2
  5. look for sample projects, if they don’t exist, start from scratch or find pieces of information you can use. Act like a detective trying to solve a mystery (Sherlock Holmes).
  6. relax, you’re going to strive eventually, the Internet is huge
Advertisements
  1. florinpiersici
    August 12, 2016 at 17:46
  1. No trackbacks yet.

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s

%d bloggers like this: