From ab48a0eade26d6407817cdb5e2cbacd7e6cb072b Mon Sep 17 00:00:00 2001 From: ngallot Date: Sat, 9 Nov 2019 13:30:02 +0100 Subject: [PATCH 1/6] add gitignore file --- .gitignore | 1 + 1 file changed, 1 insertion(+) create mode 100644 .gitignore diff --git a/.gitignore b/.gitignore new file mode 100644 index 0000000..1c2d52b --- /dev/null +++ b/.gitignore @@ -0,0 +1 @@ +.idea/* From 5869e5d828aa7f74d5e66e379b01b073c943d92e Mon Sep 17 00:00:00 2001 From: ngallot Date: Sat, 9 Nov 2019 13:30:30 +0100 Subject: [PATCH 2/6] adding venv to gitignore --- .gitignore | 1 + 1 file changed, 1 insertion(+) diff --git a/.gitignore b/.gitignore index 1c2d52b..7890186 100644 --- a/.gitignore +++ b/.gitignore @@ -1 +1,2 @@ .idea/* +venv/* \ No newline at end of file From ba278084d4aed747dc6799eefc1cc3496f78425b Mon Sep 17 00:00:00 2001 From: ngallot Date: Sat, 9 Nov 2019 13:30:49 +0100 Subject: [PATCH 3/6] writing python code and updating instructions on README --- README.md | 28 ++++++++++++++++++++++++++++ main.py | 4 ++++ 2 files changed, 32 insertions(+) create mode 100644 main.py diff --git a/README.md b/README.md index 723f3ba..f96b31d 100644 --- a/README.md +++ b/README.md @@ -1,2 +1,30 @@ # docker-python-helloworld A Python dockerized hello world app +This repo aims at showing how simple it can be to build a Docker container running a Python (very simple) app. +Once you understand how this simple example works, it's easy to apply it to bigger apps. + +### Steps to run directly the python code +It's highly recommended to install the (empty) dependencies in a virtual environment. + +- Creating the virtual environment: +```bash +virtualenv venv +``` + +- Activatingv the virtual environment: +```bash +source venv/bin/activate +``` +- Installing dependencies: +```bash +pip install -r requirements.txt +``` + +- Running the code: +```bash +python main.py +``` + + + + diff --git a/main.py b/main.py new file mode 100644 index 0000000..71010e5 --- /dev/null +++ b/main.py @@ -0,0 +1,4 @@ + + +if __name__ == '__main__': + print('Hello Docker world!') From 687679e46327818fdd871408232011173b72e77e Mon Sep 17 00:00:00 2001 From: ngallot Date: Sat, 9 Nov 2019 13:36:36 +0100 Subject: [PATCH 4/6] add unseless contents to dockerignore --- .dockerignore | 3 +++ 1 file changed, 3 insertions(+) create mode 100644 .dockerignore diff --git a/.dockerignore b/.dockerignore new file mode 100644 index 0000000..d334090 --- /dev/null +++ b/.dockerignore @@ -0,0 +1,3 @@ +.idea/* +venv/* +README.md From 8593649f657040cf42bff957495cde07f9a08600 Mon Sep 17 00:00:00 2001 From: ngallot Date: Sat, 9 Nov 2019 13:45:46 +0100 Subject: [PATCH 5/6] define container layes in Dockerfile --- Dockerfile | 11 +++++++++++ 1 file changed, 11 insertions(+) create mode 100644 Dockerfile diff --git a/Dockerfile b/Dockerfile new file mode 100644 index 0000000..24c23a0 --- /dev/null +++ b/Dockerfile @@ -0,0 +1,11 @@ +FROM python:3.7-slim + +# Add requirements file in the container +COPY requirements.txt ./requirements.txt +RUN pip install -r requirements.txt + +# Add source code in the container +COPY main.py ./main.py + +# Define container entry point (could also work with CMD python main.py) +ENTRYPOINT ["python", "main.py"] \ No newline at end of file From 674b349910629d22023e58a1819e6404099053a2 Mon Sep 17 00:00:00 2001 From: ngallot Date: Sat, 9 Nov 2019 13:48:55 +0100 Subject: [PATCH 6/6] update README to add instructions to build and run the code in a Docker container --- README.md | 12 ++++++++++++ 1 file changed, 12 insertions(+) diff --git a/README.md b/README.md index f96b31d..104c19f 100644 --- a/README.md +++ b/README.md @@ -26,5 +26,17 @@ python main.py ``` +### Steps to run the python code withing a Docker container + +- Build the image: +```bash +docker build -t docker-python-helloworld:lastest +``` + +- Run the container: +```bash +docker run docker-python-helloworld:latest +``` +