5 min read

Some cool docker picture I have decided to gather all my webs and apps in the same server. I have a virtual private server on OVH, and I wanted to set up all these things in the same server:

  • This Blog
  • My Personal Web
  • My pet project web
  • My pet project api
    • MongoDb for the api
    • Redis server for the api

I have three webs and only one port 80 but no problem, I'll use a proxy.

So a simple sketch of the platform it will be like this:

Crooquis with my schema

After a while, I got to thinking which tool would be best and I said to myself, it's time to learn Docker and enjoy the scalability and abstraction that Docker gives me. So I started to study docker's documentation to see different public containers and these are my results.

"The scope of this post is to explain which images I am using. It's not about how to install docker or how to create a Dockerfile, for that info visit the docker documentation. If you need more details on a specific matter, let me know, and I will be glad to get back to you" :)


The proxy

For this part I had two options, using the oficial nginx image and make my own config file and use a volume to share with the container or using the community creation nginx-proxy.
This image creates a container with nginx and docker-gen. docker-gen generates reverse proxy configs for nginx and reloads nginx when containers are started and stopped. It's as simple as this:

docker run -d -p 80:80 -v /var/run/docker.sock:/tmp/docker.sock:ro jwilder/nginx-proxy

docker run    The command to create a container.
-d    Detached mode, running in background.
-p 80:80    I am exposing the container to port 80 and also using the port 80 for internal mapping.
-v /var/run/docker.sock:/tmp/docker.sock:ro    I am sharing the docker sock of the host to the docker-gen inside of the container.
jwilder/nginx-proxy    This is the name of the image that I'm going to use.

For each container that we want to proxy we have to use the variable VIRTUAL_HOST and assign the url that we want to use for this container.


My blog

I am using Ghost for the blog. It's a blogging platform developed in javascript. I've heard very good things about it so I wanted to give it a try. After a simple search I found the oficial image for ghost.
For this container I created a volume in the host for the configuration, data, images and theme files.

docker run -e VIRTUAL_HOST=blog.borjafernandezpillado.com -e NODE_ENV=production -v /srv/docker/ghost:/var/lib/ghost -p 2368 --name personal-blog -d ghost

docker run    The command to create a container.
-e VIRTUAL_HOST=blog.borjafernandezpillado.com    Variable used to proxy this container through the url.
-e NODE_ENV=production    Variable used to tell ghost that it's gonna be a production instance.
-v /srv/docker/ghost:/var/lib/ghost    The volume for config files, images, themes and data
-p 2368    Port for internal use.
--name personal-blog    Name of this container
-d    Detached mode, running in background.
ghost    This is the name of the image that I am going to use.

The first time that you run this image you have to modify the config.js with the right urls and add the following code to the production section and restart the container.

paths: {
        contentPath: path.join(process.env.GHOST_CONTENT, '/')
    }


My Web

For my personal web I created my own image. I really didn't create a very difficult one, look at the Docker file:

FROM httpd:2.4

COPY ./web/ /usr/local/apache2/htdocs/

As you can see I just use the Apache Official image and copy my code to the right folder.

docker run -e VIRTUAL_HOST=borjafernandezpillado.com -p 80 --name personal-web -d yourUsername/web:1.0

docker run    The command to create a container.
-e VIRTUAL_HOST=borjafernandezpillado.com    Variable to proxy this container through the url.
-p 80    Port for internal use.
--name personal-web    Name of this container
-d    Detached mode, running in background.
yourUsername/web:1.0    Name of the image and its version.

If you want to add your specific apache config, you just have to add a line like this in your Dockerfile:

COPY ./my-httpd.conf /usr/local/apache2/conf/httpd.conf


My pet project web

This container is almost made like my personal web container; Nothing to add.

docker run -e VIRTUAL_HOST=fooproject.com -p 80 --name pet-project-web -d yourUsername/petProject-web:1.2

docker run    The command to create a container.
-e VIRTUAL_HOST=fooproject.com    Variable to proxy this container through this url.
-p 80    This container is gonna be listen through this port.
--name pet-project-web    Name of this container
-d    Detached mode, running in background.
yourUsername/pet-project-web:1.0    Name of the image and its version.

My pet project API

For this API I also made my own image. I used the Official ubuntu image, then I installed node,copied my code, installed all the dependencies and started the app. Look:

FROM ubuntu

RUN apt-get update
RUN apt-get install -y nodejs-legacy npm

COPY . /

RUN npm install

CMD npm start

For this container I used links to other containers only accessible from this one.

docker run -e VIRTUAL_HOST=fooproject.com -p 3023 --link pet-mongo:mongo --link gamis-redis:REDIS --name pet-api -d yourUsername/pet-project-api:1.0

docker run    The command to create a container.
-e VIRTUAL_HOST=fooproject.com    Variable to proxy this container through this url.
--p 3023    This container is gonna be listen through this port.
--link pet-mongo:mongo     This container is gonna be linked to pet-mongo container with an alias "mongo".
--link pet-redis:redis     This container is gonna be linked to pet-redis container with an alias "redis".
--name pet-api    Name of this container
-d    Detached mode, running in background.
yourUsername/pet-project-api:1.0    Name of the image and its version.


Redis for my pet project

I use the offcial image for redis without any change

docker run --name gamis-redis -d redis


Mongo for my pet project

I did the same with the mongo image as the redis one.

docker run --name gamis-mongo -v /srv/docker/mongo/data/db:/data/db -d mongo


This is the first post on my blog n_n please show me love sharing and commenting. Thanks a lot!!!