From 7f147fd10c1a27b0e474e69f5a76e1da9311cf7e Mon Sep 17 00:00:00 2001 From: "Andrew T. Baker" Date: Tue, 29 Apr 2014 12:05:35 -0400 Subject: [PATCH] Finalizing exercise 3 --- intro/Dockerfile | 33 ++++++++++++++++++++++----------- intro/README.rst | 8 ++++---- 2 files changed, 26 insertions(+), 15 deletions(-) diff --git a/intro/Dockerfile b/intro/Dockerfile index e115a18..a408fd4 100644 --- a/intro/Dockerfile +++ b/intro/Dockerfile @@ -3,19 +3,26 @@ FROM ubuntu:precise -MAINTAINER Andrew T. Baker +# 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 @@ -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. diff --git a/intro/README.rst b/intro/README.rst index c5f0764..3991748 100644 --- a/intro/README.rst +++ b/intro/README.rst @@ -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`` @@ -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. @@ -65,3 +63,5 @@ In the previous exericse updating the navbar text in the Django app was a somewh That's where `Dockerfiles `_ 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. +