adamkdean

software engineering

Find IP address of Docker container

By Adam K Dean on

To get the IP address of a Docker container, use the following command:

$ docker inspect --format '{{ .NetworkSettings.IPAddress }}' ${CID}

So let's say the ID of the container is a2150s, we could get the IP like so:

$ docker inspect --format '{{ .NetworkSettings.IPAddress }}' a2150s

172.17.0.2

I have written a script for this, /usr/local/bin/dockerip:

#!/bin/bash

COUNT=`docker ps | grep $1 | wc -l | bc`

if [ $COUNT -gt 0 ]; then
  IP_ADDRESS=`docker inspect --format '{{ .NetworkSettings.IPAddress }}' $1`
  echo "$1: $IP_ADDRESS"
else
  echo "Could not find $1. Check container is running."
fi

This will form part of a repository of useful docker scripts.

Local DNS resolver found in resolv.conf and containers can't use it

By Adam K Dean on

I've been playing with Docker for part of a project, and came across this annoying but important message:

WARNING: Local (127.0.0.1) DNS resolver found in resolv.conf and containers can't use it. Using default external servers : [8.8.8.8 8.8.4.4]

The problem? /etc/resolv.conf has nameserver 127.0.0.1 (or nameserver 127.0.1.1) in it.

I worked out that Ubuntu 14.04 LTS uses a daemon called dnsmasq, which routes DNS traffic through to the DNS servers provided by DHCP.

While this works fine for Docker, that message is quite annoying.

I disabled dnsmasq in /etc/NetworkManager/NetworkManager.conf:

$ sudo nano /etc/NetworkManager/NetworkManager.conf

#dns=dnsmasq

I then added the public Google DNS servers to /etc/dhcp/dhclient.conf:

$ sudo nano /etc/dhcp/dhclient.conf

prepend domain-name-servers 8.8.8.8,8.8.4.4;

Then you just need to restart NetworkManager:

$ sudo restart network-manager

And now you can start Docker containers without that pesky message!

Install Docker on Ubuntu

By Adam K Dean on

To install Docker on Ubuntu 14.04 LTS, run the following commands:

$ sudo apt-get install docker.io
$ sudo ln -sf /usr/bin/docker.io /usr/local/bin/docker

Once that is done, add your user to the docker group:

$ sudo usermod -a -G docker adam

After this, you may need to logout and login again. I had an issue where I recieved an error like this:

$ docker ps
dial unix /var/run/docker.sock permission denied

Once you've logged out and back in again, you can test docker is installed and works like so;

$ docker version
Client version: 0.9.1
Go version (client): go1.2.1
Git commit (client): 3600720
Server version: 0.9.1
Git commit (server): 3600720
Go version (server): go1.2.1
Last stable version: 0.11.1

Be sure to read up more at Getting Started

Install Sublime Text on Ubuntu

By Adam K Dean on

This relates to installing Sublime Text on Ubuntu 14.04 LTS.

For Sublime Text 2, run the following commands:

$ sudo add-apt-repository ppa:webupd8team/sublime-text-2
$ sudo apt-get update
$ sudo apt-get install sublime-text

For Sublime Text 3, run the following commands:

$ sudo add-apt-repository ppa:webupd8team/sublime-text-3
$ sudo apt-get update
$ sudo apt-get install sublime-text

Notice that it's just a case of changing sublime-text-2 to sublime-text-3.

Don't forget to Install Emmet (Zen Coding) and LESS highlighting too!

Flickr API Size enum

By Adam K Dean on

Just for future reference, here is the Flickr API sizes as a JavaScript enum.

var flickr_sizes = {
    'square':       '_s',
    'large_square': '_q',
    'thumbnail':    '_t',
    'small':        '_m',
    'small_320':    '_n',
    'medium':       '',
    'medium_640':   '_z',
    'medium_800':   '_c',
    'large':        '_b',
    'large_1600':   '_h',
    'large_2048':   '_k',
    'original':     '_o'
};