Skip to content

Commit

Permalink
Refine Dockerfile: 1. enable access from host to container 2. add a s…
Browse files Browse the repository at this point in the history
…hort guide
  • Loading branch information
zkl94 committed Aug 13, 2015
1 parent 3764e3c commit 9273434
Showing 1 changed file with 50 additions and 18 deletions.
68 changes: 50 additions & 18 deletions Dockerfile
Original file line number Diff line number Diff line change
@@ -1,52 +1,84 @@
FROM fedora:latest
# 1. Automated build:
# https://hub.docker.com/r/lao605/product-definition-center/builds/
#
###########################################
# Guide:
# 1. Use this to build a new image
# docker build -t <YOUR_NAME>/pdc <the directory your Dockerfile is located>
#
# 2. Running the container
# 2.1 To operate on the container interactively (with a terminal)
# docker run -it -p 10000:8000 <YOUR_NAME>/pdc
#
# 2.2 To run the container in daemon mode
# docker run -d -p 10000:8000 <YOUR_NAME>/pdc
#
# 3. Check the addresses
# 3.1 Check the address of the docker machine
# docker-machine env <the name of your docker machine> --> DOCKER_HOST
#
# 3.2 Check the mapped port of your running container
# docker ps -l --> PORTS
#
# 4. Access it
# Visit <DOCKER_HOST:PORTS> on your web browser
#
# For example
# if the address of the running docker machine is http://192.168.1.2 and the PORTS
# are 0.0.0.0:32816->8000/tcp. Then you can 'access' the 8000 port in the container
# by visiting http://192.168.1.2:32816 in your browser
#

FROM fedora:21
MAINTAINER Zhikun Lao <zlao@redhat.com>

LABEL Description = "product-definition-center"
LABEL Vendor = "Red Hat"
LABEL Version = "0.5"

RUN yum -y upgrade && yum install -y sudo tar git make gcc libuuid-devel python-devel swig krb5-devel koji python-mock python-ldap python-requests
# patternfly1
RUN curl https://copr.fedoraproject.org/coprs/patternfly/patternfly1/repo/fedora-21/patternfly-patternfly1-fedora-21.repo > /etc/yum.repos.d/patternfly-patternfly1-fedora-21.repo

# solve dependencies
RUN yum -y upgrade && yum install -y rpm-build sudo passwd tar git make gcc libuuid-devel python-devel python-setuptools python-pip swig krb5-devel koji python-mock python-ldap python-requests patternfly1

# add runtime user (username and password are both `dev`) and add to sudoer
RUN useradd dev -p dev
RUN useradd dev
RUN echo "dev" | passwd dev --stdin
RUN echo "dev ALL=(ALL) ALL" >> /etc/sudoers
ENV HOME /home/dev

USER dev
RUN git clone https://github.com/release-engineering/product-definition-center ${HOME}/product-definition-center

# solve dependencies and test
WORKDIR ${HOME}/product-definition-center
# install and test
USER root
WORKDIR ${HOME}/product-definition-center
# specify version of djangorestframework specifically to avoid mistake...
RUN pip install djangorestframework==3.1.3
RUN make install
RUN make test

# firewall may have block the port?
# RUN iptables -I INPUT -p tcp --dport 8000 --syn -j ACCEPT

USER dev
RUN python manage.py migrate
WORKDIR ${HOME}/product-definition-center/pdc

# change setting
USER dev
WORKDIR ${HOME}/product-definition-center/pdc
RUN cp settings_local.py.dist settings_local.py
RUN echo "DEBUG = True" >> settings_local.py

# hotfix
RUN echo "REST_FRAMEWORK = {'DEFAULT_METADATA_CLASS': 'contrib.bulk_operations.metadata.BulkMetadata'}" >> settings_local.py

# deploy
USER root
EXPOSE 8000
RUN pip install gunicorn greenlet eventlet gevent

# set up `virtualenv + virtualenvwrapper`
USER root
RUN curl -sL https://raw.githubusercontent.com/brainsik/virtualenv-burrito/master/virtualenv-burrito.sh | $SHELL

# container start as user `dev`
USER dev
WORKDIR ${HOME}

# add volume
VOLUME ${HOME}

CMD ["/bin/bash"]
EXPOSE 8000

CMD ["python", "product-definition-center/manage.py", "runserver", "0.0.0.0:8000"]

0 comments on commit 9273434

Please sign in to comment.