A really awesome feature of Docker
is container linking and volume linking.
They allow containers to communicate together and share data between them and
the host.
Lets make sure our workshop/exposing
container is running:
$ docker run -d -p 8000:8000 --name exposed -t workshop/exposing
...
$ docker ps
...
Notice the --name exposed
parameter. This is so we can reference it later.
Run /bin/bash
in another container where we link containers.
$ docker run -i --link exposed:exposed -t workshop /bin/bash
root@1234:/# env | grep sort
...
root@1234:/# cat /etc/hosts
...
With that output you can see how Docker
links containers, ENV
variables,
and hosts entries!
While still in the container:
$ apt-get install -y wget
$ wget $EXPOSED_PORT_8000_TCP_ADDR:8000
$ cat index.html
Change your Dockerfile
to this:
FROM stackbrew/ubuntu:14.04
RUN apt-get update
RUN apt-get install -y ruby-dev
EXPOSE 8000
VOLUME ["/app"]
WORKDIR /app
CMD ruby -run -e httpd . -p 8000
$ docker build -t workshop/exposing .
We need to kill our docker container and restart it:
$ docker kill $(docker ps -q)
$ docker run -d -p 8000:8000 -v /home:/app -t workshop/exposing
Navigate to http://your-ip:8000 and see what contents show up