Consul & Registrator & Rails Service all together in separate Docker container

1.Start a container running Consul:

Here we use this image: https://hub.docker.com/r/progrium/consul/

$ docker run -it -h node -p 8500:8500 -p 53:53/udp progrium/consul -server -bootstrap -advertise  $DOCKER_IP

 

How to check that Consul is running:

Method1:

In Docker-Machine, run

$ docker ps

Will see running Consul container:

3

We can also check the logs:

$ docker logs $CONTAINER_ID

3

Method2:

Browse to $DOCKER_IP:8500 there is a dashboard to see the services that are registered in Consul:

3

 

 

2.Start a container running Registrator

Here we use this image: https://hub.docker.com/r/gliderlabs/registrator/

Registrator automatically registers and deregisters services for any Docker container by inspecting containers as they come online.

Registrator watches for new Docker containers and inspects them to determine what services they provide. For our purposes, a service is anything listening on a port. Any services Registrator finds on a container, they will be added to a service registry, such as Consul or etcd.

$ docker run -it -v /var/run/docker.sock:/tmp/docker.sock -h $DOCKER_IP gliderlabs/registrator consul://$DOCKER_IP:8500

 

How to check that Registrator is running?

In Docker-Machine, run

$ docker ps

Will see running Registrator container:

3

We can also check the logs:

$ docker logs $CONTAINER_ID

3

 

 

3. Start a web service and let Registrator automatically register it on Consul

In command line, into a directory that has proper rails app, Dockerfile and docker-compose.yml file in place.

$ docker-compose build
$ docker-compose run web bundle exec rake sample_data:populate
$ docker-compose run -p 3000 -e ‘SERVICE_NAME=romui-web’ web rails s

How to check that this service is registered?

Method1:

Use Consul API:

$ curl $DOCKER_IP/v1/catalog/services

3

We can check the service details using Consul HTTP API:

$ curl http://localhost:8500/v1/catalog/service/$SERVICE_NAME

3

Method2:

Check in Consul UI:

3

 

4. Find the IP address and port of the service from Consul UI, and start using the service.

3

Now we are ready to access the service from browser:

2

 

[Consul]Error starting agent: Failed to get advertise address: Multiple private IPs found. Please configure one.

Problem: Error starting agent: Failed to get advertise address: Multiple private IPs found. Please configure one.

I’m new to Consul, so on my windows system, I was following the official guide: https://www.consul.io/intro/getting-started/agent.html

until this step:

$ consul agent -dev

and get this error:

1

 

Why got this error:

If we don’t specify a bind address, Consul will by default listen on the first private IP on the system, and this might not work.

An explanation of private IP address vs public IP address

 

Solution:

To solve the problem, we need to explicitly specify it.

Step1: Find the private IPV4 address of this system:

$ ipconfig

3

We can see from the screenshot, the IPv4 Address is 192.168.231.18.

Step2: Specify the bind address  and start the agent:

$ consul agent -dev -bind 192.168.231.18

4

From the above screenshot, we can see now the agent is successfully up and running.

Docker/Gitlab CI – Environment Set Up Guide

1. Install Docker Engine

Use Ubuntu as example, follow the official installation guide before the “Optional Configurations” section:

https://docs.docker.com/engine/installation/linux/ubuntulinux/

In “Optional Configurations” section, only need to do “Create a docker group” and “Configure a DNS server for use by Docker”.

Create a docker group:

Why: Need to do this so that we can run docker without sudo.

Test that it works:

$docker ps

Configure a DNS server for use by Docker:

Why: Need to do this so that docker engine can resolve hostnames.

Test that it works:

$docker run -it ubuntu /bin/bash

$ping archive.ubuntu.com

An example error screenshot of not having this configured:

1
2. Install Docker Compose

Follow official guide: https://docs.docker.com/compose/install/
3. Install GitLab CI Runner and register multiple runners to use with Docker

Follow this guide: https://littletechblogger.wordpress.com/2016/03/28/install-and-set-up-gitlab-ci-runner-to-use-docker/
4. Set up job to clean non-tagged images and stopped containers

Use meltwater/docker-cleanup:  https://hub.docker.com/r/meltwater/docker-cleanup/

USB storage capacity reduced to 2MB from 14GB

Problem:

I created a bootable USB stick on Windows. Then My USB storage capacity reduced to 2MB from 14GB.

1

 

Solution:

Step1:

Follow the steps from this link: http://askubuntu.com/questions/289971/usbs-storage-capacity-reduced-to-2-mb-from-16-gb

The following is the screenshot of what I did:

10

Step2:

Now we can see that Used space and Free space both become 0 bytes:

3

Step3:

We need to format the disk:

4

Step4:

After formatting, we could see that the USB’s capacity turns back to be normal:

5