Skip to content

Instantly share code, notes, and snippets.

@kstrauss
Last active April 26, 2019 16:22
Show Gist options
  • Save kstrauss/64632f7d769b0bd1bfb05f5ff75d517b to your computer and use it in GitHub Desktop.
Save kstrauss/64632f7d769b0bd1bfb05f5ff75d517b to your computer and use it in GitHub Desktop.
Simple example of python and docker. This as an idea of how perhaps we could offer a general way deploying some code from a git repo into a python container. The main question to me is how should things be triggered/scheduled.
# This dockerfile utilizes components licensed by their respective owners/authors.
# Prior to utilizing this file or resulting images please review the respective licenses at: https://docs.python.org/3/license.html
# choose a base container, in this case a windowsServerCore but it could have been a linux one
# like ubuntu or alpine
FROM microsoft/windowsservercore
LABEL Description="Python" Vendor="Python Software Foundation" Version="3.7.3"
# go acquire the version of python and then do a quiet install
RUN powershell.exe -Command \
$ErrorActionPreference = 'Stop'; \
[Net.ServicePointManager]::SecurityProtocol = [Net.SecurityProtocolType]::Tls12; \
wget https://www.python.org/ftp/python/3.7.3/python-3.7.3.exe -OutFile c:\python-3.7.3.exe ; \
Start-Process c:\python-3.7.3.exe -ArgumentList '/quiet InstallAllUsers=1 PrependPath=1' -Wait ; \
Remove-Item c:\python-3.7.3.exe -Force
# create directory to copy files to
RUN mkdir c:\runTest
# copy the files that should have come from git
COPY numpyTest.py c:/runTest/numpyTest.py
copy requirements.txt c:/runTest/requirements.txt
# go ahead and install the python modules that also came from git
RUN pip install -r c:/runTest/requirements.txt
# create a simple python script
#RUN echo print("Hello World from python from a container!") > c:\hello.py
# establish what command will run when the docker run command is executed
CMD ["py", "c:/runTest/numpyTest.py"]
#CMD ["py", "c:/hello.py"]
# simple numpy exercise
import numpy as np
print ("start")
a = np.arange(15).reshape(3,5)
print (a)
print ("Done")

Concerns

  • monitoring
    • is this the job of our container runner (i.e. cloud foundry)
  • how to kick off?
    • orchestration if there are several apps/containers that need to run? Is this part of cloud foundry or another piece that may be required?
  • what's the guidance of how to provide data to be used?
    • should it be the job of the python code to acquire (from files via scp, query a db)? Something else?

Problems to solve

Problem with PoC

  • should be linux based ?
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment