Skip to content

Instantly share code, notes, and snippets.

@krhoyt
Created April 20, 2024 20:17
Show Gist options
  • Save krhoyt/59107adc484e56dcc825cdf5c03a7846 to your computer and use it in GitHub Desktop.
Save krhoyt/59107adc484e56dcc825cdf5c03a7846 to your computer and use it in GitHub Desktop.
Docker as Python Environment
docker build -t krhoyt/hello:1.0 .
FROM python:latest
WORKDIR /usr/local/bin
COPY requirements.txt .
RUN pip install -r requirements.txt
RUN mkdir input
RUN mkdir output
COPY hello.py .
ENTRYPOINT ["python", "hello.py"]
import os
import sys
print( sys.version )
output = "Hello world!"
if len( sys.argv ) == 1:
if os.path.isfile( "input/name.txt" ):
file = open( "input/name.txt", "r" )
content = file.read()
file.close()
output = "Hello {}!".format( content )
else:
output = "Hello {}!".format( sys.argv[1] )
file = open( "output/greeting.txt", "a" )
file.write( output )
file.close()
print( output )
docker run -ti -v /_absolute_local_path_/input:/usr/local/bin/input -v /_absolute_local_path_/output:/usr/local/bin/output --rm --name hello krhoyt/hello:1.0
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment