Docker Workshop


Exposing Ports and CMD

Running confined containers is useful and fun, but what if we could open up some ports to communicate with the outside world?

Exposing Ports

Replace your Dockerfile with this one:

FROM stackbrew/ubuntu:14.04
RUN apt-get update
RUN apt-get install -y ruby-dev

EXPOSE 8000

Now build it:

$ docker build -t workshop/exposing .
...

Make sure it works:

$ docker run -i -t workshop/exposing ruby --version
ruby 1.9.3p484 (2013-11-22 revision 43786) [x86_64-linux]

Lets use the port 8000:

$ docker run -i -p 8000:8000 -t workshop/exposing ruby -run -e httpd /var/log -p 8000

Now navigate to http://your-ip:8000

Custom container commands

Now that we have a long running task to run, what if I told you you didn't have to type your command every time???

Replace your Dockerfile with this one:

FROM stackbrew/ubuntu:14.04
RUN apt-get update
RUN apt-get install -y ruby-dev

EXPOSE 8000
CMD ruby -run -e httpd . -p 8000
$ docker build -t workshop/exposing .

Now we can just run the image with:

$ docker run -i -p 8000:8000 -t workshop/exposing

Ops now can run your app with NO knowledge of your app! Mostly...

Exercises