Thursday, January 22, 2015

extra Docker networking goodies

I work a great deal with Docker, connecting webservers and databases together, hiding everything behind a caching proxy like Nginx.  Docker is a wonderful tool, providing isolation and semi-magical capabilities like hiding an entire "cluster" of machines behind a single container, a single process.

However containers are not much fun. They're generally so stripped down as to make debugging issues rather more awkward than normal.  The following questions are common when something doesn't work:

  • is my process running on the correct port?
  • what processes are running?
  • which services are up, on which ports?

With a default Docker container, answers to these questions aren't obvious.

Solution: add the following to all of your Dockerfiles:

RUN apt-get update && apt-get install -y apt-file curl net-tools procps psmisc
# 'psmisc' provides /bin/fuser; procps=>/bin/ps; net-tools=>netstat

Here's an example Nginx Dockerfile which 1) lets me verify Nginx is running on the right port and happy, and 2) when I hop into the container with "docker exec", I can use normal tools to see what's going on.

FROM nginx:1.7
RUN apt-get update && apt-get install -y apt-file curl net-tools procps psmisc
# 'psmisc' provides /bin/fuser; procps=>/bin/ps; net-tools=>netstat
ADD index.html /usr/share/nginx/html/index.html
ADD nginx.conf /etc/nginx.conf


No comments:

Post a Comment