Dockerfile example

An example docker file.

Note a RUN in docker file will commit changes to the build

A CMD command is run when the docker container is run. There is only one CMD per docker build.

FROM parent_image:v1

LABEL Remarks="xyz image"

WORKDIR /app

COPY . /app

#run yum clean all after every yum to clean up and avoid rpmdb checksum invalid error.

RUN yum install -y openssl ; yum clean all

#temporily disable the local ABC.repo. this can be done through repo manager as well.

RUN mv /etc/yum.repos.d/ABC.repo /etc/yum.repos.d/ABC.repo.bak

#copy the external ms odbc repo , the mssql-release.repo file is included in the docker build folder

RUN mv mssql-release.repo /etc/yum.repos.d/mssql-release.repo

#backup the yum.conf and put in proxy settings, so as to access the ms odbc repo

RUN cp /etc/yum.conf /etc/yum.conf.bak

RUN echo "proxy=http://myproxy:8080" >> /etc/yum.conf && \

    echo "proxy_username=user" >> /etc/yum.conf && \

echo "proxy_password=password" >> /etc/yum.conf

RUN ACCEPT_EULA=Y yum install -y msodbcsql17; yum clean all

RUN mv /etc/yum.conf.bak /etc/yum.conf

#copy the local repo back and disable the ms odbc repo

RUN mv /etc/yum.repos.d/ABC.repo.bak /etc/yum.repos.d/ABC.repo

RUN mv /etc/yum.repos.d/mssql-release.repo /etc/yum.repos.d/mssql-release.repo.bak

#install packages through yum

RUN yum install -y pyodbc ; yum clean all

RUN yum install -y gcc  ; yum clean all

RUN yum install -y python2-pip ; yum clean all

#install python stuff

RUN pip install --upgrade pip --proxy http://myproxy:8080

RUN pip install flask --proxy http://myproxy:8080

RUN pip install gunicorn --proxy http://myproxy:8080

RUN pip install numpy --proxy http://myproxy:8080

RUN pip install scipy --proxy http://myproxy:8080

RUN pip install xgboost --proxy http://myproxy:8080

#open the port number

EXPOSE 8080

#run the gunicorn command to start the service when running the docker image

#the my_module.py is the flask service script included in the docker build folder.

#start the flask service through gunicorn at 8080

#when running a docker container, use docker run -P 8080:8081 my_image:v1 to map port 8080 to port 8081

CMD ["gunicorn", "-b 0.0.0.0:8080", "my_module:my_service"]