Created
April 20, 2024 20:17
-
-
Save krhoyt/59107adc484e56dcc825cdf5c03a7846 to your computer and use it in GitHub Desktop.
Docker as Python Environment
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
docker build -t krhoyt/hello:1.0 . |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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"] |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 ) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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