Some format and syntax changes.

* Added sudo as per convention to docker commands
* Break the Dockerfile block up
* Redis is a proper noun
* Minor whitespace fixes
This commit is contained in:
James Turnbull 2013-11-02 17:41:35 -07:00
parent feef16bd88
commit c33d26a8da
2 changed files with 26 additions and 20 deletions

View file

@ -75,6 +75,7 @@ Hector Castro <hectcastro@gmail.com>
Hunter Blanks <hunter@twilio.com>
Isao Jonas <isao.jonas@gmail.com>
James Carr <james.r.carr@gmail.com>
James Turnbull <james@lovedthanlost.net>
Jason McVetta <jason.mcvetta@gmail.com>
Jean-Baptiste Barth <jeanbaptiste.barth@gmail.com>
Jeff Lindsay <progrium@gmail.com>

View file

@ -9,12 +9,14 @@ Linking Redis
.. include:: example_header.inc
Building a redis container to link as a child of our web application.
Building a Redis container to link as a child of our web application.
Building the redis container
Building the Redis container
----------------------------
Lets build a redis image with the following Dockerfile.
Lets build a Redis image with the following Dockerfile.
First checkout the Redis source code.
.. code-block:: bash
@ -22,7 +24,10 @@ Lets build a redis image with the following Dockerfile.
cd redis
git checkout 2.6
# Save this Dockerfile to the root of the redis repository.
Now let's create a Dockerfile in the root of the Redis repository.
.. code-block:: bash
# Build redis from source
# Make sure you have the redis source code checked out in
@ -51,37 +56,37 @@ Lets build a redis image with the following Dockerfile.
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
to connect to our Redis container on. If you do not expose any ports for the
image then docker will not be able to establish the link between containers.
Run the redis container
Run the Redis container
-----------------------
.. code-block:: bash
docker run -d -e PASSWORD=docker -name redis redis-2.6 --requirepass docker
sudo docker run -d -e PASSWORD=docker -name redis redis-2.6 --requirepass docker
This will run our redis container with the password docker
This will run our Redis container with 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
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 server we did not use
the ``-p`` flag to publish the redis port to the host system. Redis exposed port 6379 via the Dockerfile
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 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.
Now let's start our web application with a link into Redis.
.. code-block:: bash
docker run -t -i -link redis:db -name webapp ubuntu bash
sudo docker run -t -i -link redis:db -name webapp ubuntu bash
root@4c01db0b339c:/# env
@ -128,5 +133,5 @@ network and environment information from the containers that are linked into it.
Accessing the network information along with the environment of the child container allows
us to easily connect to the redis service on the specific ip and port and use the password
us to easily connect to the Redis service on the specific IP and port and use the password
specified in the environment.