Update links and host integration documentation

This commit is contained in:
Michael Crosby
2013-10-30 13:11:02 -07:00
parent 596facd124
commit 1edde0e8a3
2 changed files with 57 additions and 117 deletions
+28 -22
View File
@@ -14,12 +14,16 @@ Building a redis container to link as a child of our web application.
Building the redis container
----------------------------
We will use a pre-build version of redis from the index under
the name ``crosbymichael/redis``. If you are interested in the
Dockerfile that was used to build this container here it is.
Lets build a redis image with the following Dockerfile.
.. code-block:: bash
git clone https://github.com/antirez/redis.git
cd redis
git checkout 2.6
# Save this Dockerfile to the root of the redis repository.
# Build redis from source
# Make sure you have the redis source code checked out in
# the same directory as this Dockerfile
@@ -34,7 +38,6 @@ Dockerfile that was used to build this container here it is.
ADD . /redis
RUN (cd /redis && make)
RUN (cd /redis && make test)
RUN mkdir -p /redis-data
VOLUME ["/redis-data"]
@@ -43,6 +46,9 @@ Dockerfile that was used to build this container here it is.
ENTRYPOINT ["/redis/src/redis-server"]
CMD ["--dir", "/redis-data"]
# docker build our new redis image from source
docker build -t redis-2.6 .
We need to ``EXPOSE`` the default port of 6379 so that our link knows what ports
to connect to our redis container on. If you do not expose any ports for the
@@ -54,31 +60,28 @@ Run the redis container
.. code-block:: bash
docker run -d -e PASSWORD=docker -name redis crosbymichael/redis --requirepass=docker
docker run -d -e PASSWORD=docker -name redis redis-2.6 --requirepass docker
This will run our redis container using the default port of 6379 and using docker
as password to secure our service. By specifying the ``-name`` flag on run
we will assign the name ``redis`` to this container.
We can issue all the commands that you would expect; start, stop, attach, using the name.
The name also allows us to link other containers into this one. If you do not specify a
name on docker run, docker will automatically generate a name for your container.
This will run our redis container wit the password docker
to secure our service. By specifying the ``-name`` flag on run
we will assign the name ``redis`` to this container. If we do not specify a name for
our container via the ``-name`` flag docker will automatically generate a name for us.
We can issue all the commands that you would expect; start, stop, attach, using the name for our container.
The name also allows us to link other containers into this one.
Linking redis as a child
------------------------
Next we can start a new web application that has a dependency on redis and apply a link
to connect both containers. If you noticed when running our redis service we did not use
the ``-p`` option to publish the redis port to the host system. Redis exposed port 6379
but we did not publish the port. This allows docker to prevent all network traffic to
the redis container except when explicitly specified within a link. This is a big win
for security.
to connect both containers. If you noticed when running our redis server we did not use
the ``-p`` flag to publish the redis port to the host system. Redis exposed port 6379 via the Dockerfile
and this is all we need to establish a link.
Now lets start our web application with a link into redis.
.. code-block:: bash
docker run -t -i -link /redis:db -name webapp ubuntu bash
docker run -t -i -link redis:db -name webapp ubuntu bash
root@4c01db0b339c:/# env
@@ -101,22 +104,25 @@ Now lets start our web application with a link into redis.
When we inspect the environment of the linked container we can see a few extra environment
variables have been added. When you specified ``-link /redis:db`` you are telling docker
to link the container named ``/redis`` into this new container with the alias ``db``.
variables have been added. When you specified ``-link redis:db`` you are telling docker
to link the container named ``redis`` into this new container with the alias ``db``.
Environment variables are prefixed with the alias so that the parent container can access
network and environment information from the child.
network and environment information from the containers that are linked into it.
.. code-block:: bash
# The name of the child container
DB_NAME=/webapp/db
# The default protocol, ip, and port of the service running in the container
DB_PORT=tcp://172.17.0.8:6379
# A specific protocol, ip, and port of various services
DB_PORT_6379_TCP=tcp://172.17.0.8:6379
DB_PORT_6379_TCP_PROTO=tcp
DB_PORT_6379_TCP_ADDR=172.17.0.8
DB_PORT_6379_TCP_PORT=6379
# Get environment variables of the container
DB_ENV_PASSWORD=dockerpass