Skip to content

Commit

Permalink
Finalizing exercise 3
Browse files Browse the repository at this point in the history
  • Loading branch information
atbaker committed Apr 29, 2014
1 parent 8da32b8 commit 7f147fd
Show file tree
Hide file tree
Showing 2 changed files with 26 additions and 15 deletions.
33 changes: 22 additions & 11 deletions intro/Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -3,19 +3,26 @@

FROM ubuntu:precise

MAINTAINER Andrew T. Baker <[email protected]>
# Add yourself as maintainer
MAINTAINER

# Add the Django app to the container and install its requirements
ADD sd_sample_project /var/www/django
# The ENV command applies environment variables to the rest of the build steps.
# Add these environment variables to the build:
# PYTHONPATH=$PYTHONPATH:/var/www/django/sd_sample_project
# DJANGO_SETTINGS_MODULE=sd_sample_project.settings.production
# SECRET_KEY no-so-secret # Fix for your own site!

# Add a command to copy the sd_sample_project to the /var/www/django directory
# in the image
# (your command here)

# Install pip and requirements
RUN DEBIAN_FRONTEND=noninteractive apt-get install -y python-pip
RUN pip install virtualenv
RUN virtualenv /var/www/venv
RUN /var/www/venv/bin/pip install -r /var/www/django/requirements/production.txt

# Syncdb (a sqlite3 database for simplicity)
ENV PYTHONPATH $PYTHONPATH:/var/www/django/sd_sample_project
ENV DJANGO_SETTINGS_MODULE sd_sample_project.settings.production
ENV SECRET_KEY no-so-secret # Fix for your own site!
RUN /var/www/venv/bin/django-admin.py syncdb --migrate --noinput
RUN /var/www/venv/bin/django-admin.py collectstatic --noinput

Expand All @@ -24,12 +31,16 @@ RUN mkdir /var/log/gunicorn
RUN touch /var/log/gunicorn/access.log
RUN touch /var/log/gunicorn/error.log

# Add project to PYTHONPATH
RUN echo PYTHONPATH=$PYTHONPATH:/var/www/django/sd_sample_project >> /root/.bashrc

# Clean up APT when done
RUN apt-get clean && rm -rf /var/lib/apt/lists/* /tmp/* /var/tmp/*

EXPOSE 80
# Add a command to expose port 80 to the host container
# (your command here)

# Add a CMD statement to start the gunicorn server. The basic command is:
# /var/www/venv/bin/gunicorn sd_sample_project.wsgi:application
# (your command here)

CMD /var/www/venv/bin/gunicorn sd_sample_project.wsgi:application --bind 0.0.0.0:80
# HINT: You also need to use the --bind option to tell gunicorn to respond to
# requests from all hosts, since all incoming requests through docker will
# appear to be from another machine.
8 changes: 4 additions & 4 deletions intro/README.rst
Original file line number Diff line number Diff line change
Expand Up @@ -36,8 +36,7 @@ Exercise 2: Fire it up!

It's time to start your first Docker containers!

.. HINT::
I won't provide all the answers here. To complete this (and future) exercises, you will need to use the Docker docs (http://docs.docker.io/) and your intuition!
*I won't provide all the answers here. To complete this (and future) exercises, you will need to use the Docker docs (http://docs.docker.io/) and your intuition!*

Pull down this docker image from the docker index: ``atbaker/sd-django``

Expand All @@ -49,8 +48,7 @@ Now let's say we wanted to update the navbar header on the homepage to be "Sampl

Start a container with the ``atbaker/sd-django`` image again, this time in an interactive shell. Use a text editor of your choice to update the navbar text. Then exit the shell session.

.. HINT::
You rarely need to use the full container/image ID value when issuing commands to the docker client. Usually the first few characters are sufficient.
*You rarely need to use the full container/image ID value when issuing commands to the docker client. Usually the first few characters are sufficient.*

That edit was just to a single container. If we want that edit to be included next time we start a new container from this image, we need to commit the change to a new image.

Expand All @@ -65,3 +63,5 @@ In the previous exericse updating the navbar text in the Django app was a somewh

That's where `Dockerfiles <http://docs.docker.io/reference/builder/>`_ come in. Dockerfiles and the ``docker build`` command programatically build your docker images. If you keep your Dockerfile with your source code, you can include the latest source every time you build your docker image (perhaps with a Continuous Integration service).

In the **intro** subdirectory, you will find the source code for the sample Django project and a partially completed Dockerfile. **Complete the Dockerfile and use ``docker build`` to create a new image for this Django app.** Then create a container from that image to test if it works.

0 comments on commit 7f147fd

Please sign in to comment.