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 diff --git a/.gitignore b/.gitignore new file mode 100644 index 0000000..7890186 --- /dev/null +++ b/.gitignore @@ -0,0 +1,2 @@ +.idea/* +venv/* \ No newline at end of file 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 diff --git a/README.md b/README.md index 723f3ba..104c19f 100644 --- a/README.md +++ b/README.md @@ -1,2 +1,42 @@ # 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 +``` + + +### 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 +``` + + + 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!')