0

This example builds fine:

root@mordor:~/gitrepo/path-to-kubernetes/src/python/helloworld# 
root@mordor:~/gitrepo/path-to-kubernetes/src/python/helloworld# ll
total 16
drwxr-xr-x 2 root root 4096 Oct  4 15:11 ./
drwxr-xr-x 3 root root 4096 Oct  4 15:09 ../
-rw-r--r-- 1 root root  134 Oct  4 15:10 Dockerfile
-rw-r--r-- 1 root root  290 Oct  4 15:11 helloworld.py
root@mordor:~/gitrepo/path-to-kubernetes/src/python/helloworld# 
root@mordor:~/gitrepo/path-to-kubernetes/src/python/helloworld# cat Dockerfile 
FROM python:3
ADD helloworld.py /
RUN pip install flask
RUN pip install flask_restful
EXPOSE 3333
CMD [ "python", "./helloworld.py"]

root@mordor:~/gitrepo/path-to-kubernetes/src/python/helloworld# 
root@mordor:~/gitrepo/path-to-kubernetes/src/python/helloworld# cat helloworld.py 
from flask import Flask, request
from flask_restful import Resource, Api

app = Flask(__name__)
api = Api(app)

class Greeting (Resource):
    def get(self):
        return 'Hello World!'

api.add_resource(Greeting, '/') # Route_1

if __name__ == '__main__':
    app.run('0.0.0.0','3333')

root@mordor:~/gitrepo/path-to-kubernetes/src/python/helloworld# 
root@mordor:~/gitrepo/path-to-kubernetes/src/python/helloworld# git config --get remote.origin.url
https://github.com/donschenck/path-to-kubernetes
root@mordor:~/gitrepo/path-to-kubernetes/src/python/helloworld# 
root@mordor:~/gitrepo/path-to-kubernetes/src/python/helloworld# docker build -t hello-world-python .
Sending build context to Docker daemon  3.072kB
Step 1/6 : FROM python:3
3: Pulling from library/python
57df1a1f1ad8: Pull complete 
71e126169501: Pull complete 
1af28a55c3f3: Pull complete 
03f1c9932170: Pull complete 
65b3db15f518: Pull complete 
3e3b8947ed83: Pull complete 
f156949921a1: Pull complete 
1c1931013093: Pull complete 
51fff639b6bf: Pull complete 
Digest: sha256:1a126607adde46a706e76357c910f36b9f5529fb575d4d86a639a4997daceba7
Status: Downloaded newer image for python:3
 ---> bbf31371d67d
Step 2/6 : ADD helloworld.py /
 ---> 5fd4d1c7c5b7
Step 3/6 : RUN pip install flask
 ---> Running in d96dce20ef48
Collecting flask
  Downloading Flask-1.1.2-py2.py3-none-any.whl (94 kB)
Collecting Werkzeug>=0.15
  Downloading Werkzeug-1.0.1-py2.py3-none-any.whl (298 kB)
Collecting itsdangerous>=0.24
  Downloading itsdangerous-1.1.0-py2.py3-none-any.whl (16 kB)
Collecting click>=5.1
  Downloading click-7.1.2-py2.py3-none-any.whl (82 kB)
Collecting Jinja2>=2.10.1
  Downloading Jinja2-2.11.2-py2.py3-none-any.whl (125 kB)
Collecting MarkupSafe>=0.23
  Downloading MarkupSafe-1.1.1-cp38-cp38-manylinux1_x86_64.whl (32 kB)
Installing collected packages: Werkzeug, itsdangerous, click, MarkupSafe, Jinja2, flask
Successfully installed Jinja2-2.11.2 MarkupSafe-1.1.1 Werkzeug-1.0.1 click-7.1.2 flask-1.1.2 itsdangerous-1.1.0
Removing intermediate container d96dce20ef48
 ---> 7b0531de077e
Step 4/6 : RUN pip install flask_restful
 ---> Running in fe7ef1bb09cc
Collecting flask_restful
  Downloading Flask_RESTful-0.3.8-py2.py3-none-any.whl (25 kB)
Collecting six>=1.3.0
  Downloading six-1.15.0-py2.py3-none-any.whl (10 kB)
Collecting aniso8601>=0.82
  Downloading aniso8601-8.0.0-py2.py3-none-any.whl (43 kB)
Collecting pytz
  Downloading pytz-2020.1-py2.py3-none-any.whl (510 kB)
Requirement already satisfied: Flask>=0.8 in /usr/local/lib/python3.8/site-packages (from flask_restful) (1.1.2)
Requirement already satisfied: Jinja2>=2.10.1 in /usr/local/lib/python3.8/site-packages (from Flask>=0.8->flask_restful) (2.11.2)
Requirement already satisfied: click>=5.1 in /usr/local/lib/python3.8/site-packages (from Flask>=0.8->flask_restful) (7.1.2)
Requirement already satisfied: Werkzeug>=0.15 in /usr/local/lib/python3.8/site-packages (from Flask>=0.8->flask_restful) (1.0.1)
Requirement already satisfied: itsdangerous>=0.24 in /usr/local/lib/python3.8/site-packages (from Flask>=0.8->flask_restful) (1.1.0)
Requirement already satisfied: MarkupSafe>=0.23 in /usr/local/lib/python3.8/site-packages (from Jinja2>=2.10.1->Flask>=0.8->flask_restful) (1.1.1)
Installing collected packages: six, aniso8601, pytz, flask-restful
Successfully installed aniso8601-8.0.0 flask-restful-0.3.8 pytz-2020.1 six-1.15.0
Removing intermediate container fe7ef1bb09cc
 ---> 248ac954078c
Step 5/6 : EXPOSE 3333
 ---> Running in 9681adbfde78
Removing intermediate container 9681adbfde78
 ---> 34aada583093
Step 6/6 : CMD [ "python", "./helloworld.py"]
 ---> Running in 268bb644239b
Removing intermediate container 268bb644239b
 ---> 148a79ef9a18
Successfully built 148a79ef9a18
Successfully tagged hello-world-python:latest
root@mordor:~/gitrepo/path-to-kubernetes/src/python/helloworld# 
root@mordor:~/gitrepo/path-to-kubernetes/src/python/helloworld# docker run -p 3333:3333 hello-world-python
 * Serving Flask app "helloworld" (lazy loading)
 * Environment: production
   WARNING: This is a development server. Do not use it in a production deployment.
   Use a production WSGI server instead.
 * Debug mode: off
 * Running on http://0.0.0.0:3333/ (Press CTRL+C to quit)
172.17.0.1 - - [04/Oct/2020 22:31:39] "GET / HTTP/1.1" 200 -

and generates the correct output:

nicholas@mordor:~$ 
nicholas@mordor:~$ curl http://localhost:3333
"Hello World!"
nicholas@mordor:~$ 

But I'm more interested in a classic sort of "console" app, or is that just not how docker works? There pretty much has to be a web server such as flask involved to get output?

This sort of "console" type output:

root@mordor:~# 
root@mordor:~# docker run hello-world

Hello from Docker!
This message shows that your installation appears to be working correctly.

To generate this message, Docker took the following steps:
 1. The Docker client contacted the Docker daemon.
 2. The Docker daemon pulled the "hello-world" image from the Docker Hub.
    (amd64)
 3. The Docker daemon created a new container from that image which runs the
    executable that produces the output you are currently reading.
 4. The Docker daemon streamed that output to the Docker client, which sent it
    to your terminal.

To try something more ambitious, you can run an Ubuntu container with:
 $ docker run -it ubuntu bash

Share images, automate workflows, and more with a free Docker ID:
 https://hub.docker.com/

For more examples and ideas, visit:
 https://docs.docker.com/get-started/

root@mordor:~# 

is pretty much useless for messaging between containers?

A poor-man's Apache ActiveMQ was what I had in mind.

4
  • 1
    welcome to DevOps SE! it sounds to me that you are looking on two different use cases? some people use containers to run services, but some need indeed a packaged "CLI", examples are maven and terraform. Have a look: attosol.com/using-docker-for-distributing-command-line-tools is this what you are looking for? – Peter Muryshkin Oct 6 '20 at 13:16
  • 1
    Are you trying to pipe output (stdout) from one containers console as input into some other process? – Danny Staple Oct 6 '20 at 15:47
  • yes @DannyStaple that's the question which I meant to ask. But surely there's a multitude of messaging options available. – Nicholas Saunders Oct 7 '20 at 11:55
  • 1
    Oh definitely, REST, MQs, ip packets, crude file based polling, db polling. It depends on what you are trying to do. – Danny Staple Oct 7 '20 at 16:54

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Browse other questions tagged or ask your own question.