diff --git a/docker/hands-on/python-sample/Dockerfile b/docker/hands-on/python-sample/Dockerfile new file mode 100644 index 00000000..c516cba0 --- /dev/null +++ b/docker/hands-on/python-sample/Dockerfile @@ -0,0 +1,6 @@ +FROM python:3.8 +WORKDIR / +COPY requirements.txt . +# RUN pip install -r requirements.txt +COPY . . +CMD [ "python", "random.py" ] diff --git a/docker/hands-on/python-sample/README.md b/docker/hands-on/python-sample/README.md new file mode 100644 index 00000000..df89c925 --- /dev/null +++ b/docker/hands-on/python-sample/README.md @@ -0,0 +1 @@ +[Link to practice script](practice.sh) diff --git a/docker/hands-on/python-sample/basic.py b/docker/hands-on/python-sample/basic.py new file mode 100644 index 00000000..a3ea3c68 --- /dev/null +++ b/docker/hands-on/python-sample/basic.py @@ -0,0 +1 @@ +print("Hello") \ No newline at end of file diff --git a/docker/hands-on/python-sample/practice.sh b/docker/hands-on/python-sample/practice.sh new file mode 100644 index 00000000..a53f7808 --- /dev/null +++ b/docker/hands-on/python-sample/practice.sh @@ -0,0 +1,11 @@ +#!/bin/bash + +# Running python script without building docker image +echo "Running python script without building docker image" +docker run --rm -v $(pwd):/app -w /app python:3.9-slim-buster python basic.py +echo $? +# Build and run docker container +echo "Build and run docker container" +IMAGE_NAME="random_python:latest" +docker build -t $IMAGE_NAME . +docker run --rm $IMAGE_NAME diff --git a/docker/hands-on/python-sample/random.py b/docker/hands-on/python-sample/random.py new file mode 100644 index 00000000..2ebc743c --- /dev/null +++ b/docker/hands-on/python-sample/random.py @@ -0,0 +1,4 @@ +import datetime +now = datetime.datetime.now() +print ("Current date and time : ") +print (now.strftime("%Y-%m-%d %H:%M:%S")) diff --git a/docker/hands-on/python-sample/requirements.txt b/docker/hands-on/python-sample/requirements.txt new file mode 100644 index 00000000..a1e4bc59 --- /dev/null +++ b/docker/hands-on/python-sample/requirements.txt @@ -0,0 +1 @@ +random