Creating an image with A Dockerfile

Standard

The Dockerfile

Simply a file or manifest that has all the commands needed to be run to create an image when you run ‘docker build’. You can find more information here: Dockerfile docs

Simple Dockerfile

Just to keep it simple a Dockerfile can be as simple as installing packages after setting up a server and creating some directories. Here’s an example:

Here is a Dockerfile I used for a virtual host apache image:
https://github.com/mfung/alpine_apache2_php7

Commands

Some commands when dealing with building an image:

 

Using Docker-compose

Standard

Automating

Commands for docker-compose

You will need a YAML file that contains your stack.

Stack file

A little more complex example: https://gist.github.com/mfung/9b0fd65ccc793c7b1ec44dfb2deb370d

Install & Using Docker (OSX, CoreOS, Docker-CM, Alpine Linux, Docker-Compose)

Standard

I recently decided to consolidate some of my websites onto one server. I also wanted to https (SSL) most if not all my websites. Before I would use CentOS or Ubuntu and Nginx as a reverse proxy with Nginx/Passenger serving my Rails apps and Apache/PHP serving my WordPress/PHP sites. Here’s how I installed docker, docker-cm and started using containers on my production servers.

I’ve known about Docker and I’ve used it indirectly, a Rails app i worked on used it in production but it was abstracted from us software engineers. So I installed Docker-CM on both CentOS, Ubuntu, and Docker on OSX to experiment.

OSX: https://docs.docker.com/docker-for-mac/install/

After spinning up some containers and learning some Docker commands.

Docker Commands

I started to research minimalist Linux distros for the host OS. I only need to be able to run Docker-CM, maybe a firewall, and some other minimal software on it because the heavy lifting would be done in each of the containers. While doing that I learned about Alpine Linux for the container image. I was using CentOS and Ubuntu images at first and while looking at host images and file sizes I realized I can be more efficient with the containers as well.

Docker Images

REPOSITORYTAGSIZE (MB)
alpinelatest4.15
centoslatest207.0
ubuntulatest111.0
busyboxlatest1.14

Now why I didn’t use BusyBox instead of Alpine. I just found alpine and apk easy and familiar. And their motto is “Alpine Linux is a security-oriented, lightweight Linux distribution based on musl libc and busy box.” I like security, I like lightweight, and I like Linux.

With all this playing around and researching, I found docker-compose and read up on creating a Dockerfile. I also ran across some important images:

postgres:10.1-alpine
nginx:alpine
jrcs/letsencrypt-nginx-proxy-companion
jwilder/docker-gen
WordPress (there are different flavors of alpine, apache, and different versions of PHP)

What I wanted in my ecosystem is Postgres (Phoenix, Rails, and my goto DB), MySQL (for my WordPress sites), Redis, MongoDB + R, Nginx Proxy, Apache Virtual Hosting not just 1 instance of WordPress per container.

Next