Code Monkey home page Code Monkey logo

pysimple's Introduction

PySimple

GitHub GitHub tag (latest SemVer)

Ansible Role

Build and push latest image Build and push release image

A very simple Python application. Using the material in Docker's Get Started guide this is a simple (classic) Python-based web-app that uses Flask and Redis. You don't have to understand any of this, the goal of this project is simply to provide a stable base for demonstrating Docker.

You should be able to build and run the containerised app using any suitably equipped Docker host. I used a Mac and Docker 20.10.11.

Building

Build and tag the image...

$ docker build -t friendlyhello .

And run it (in detached/non-blocking mode)...

$ docker run -d -p 4000:8080 friendlyhello
<container ID>

This will start the image as a container and map host port 4000 into the container's on port 8080. This port re-mapping is an essential part of the Docker ecosystem. The long-and-short of all of this is that you should now be able to connect to the app at http://localhost:4000:

$ curl http://localhost:4000

Now stop your container and remove the stopped container using its ID:

$ docker stop <container ID>
$ docker rm <container ID>

You can also use docker-compose and the built-in docker-compose.yml configuration file to build and launch more than one container. In our compose file we start the PySimple container but also start a Redis container, a simple database that the app will use (if it can) to count the number of visits made to its port.

$ docker-compose build
$ docker-compose up --detach

The docker-compose configuration exposes the application container using port 8080 on the local host.

And stop and remove the containers with: -

$ docker-compose down

Deploying to Docker Hub

Here, we'll deploy to the Docker hub. It's free and simple. We just need to tag our image and then push it.

$ docker login -u alanbchristie
[...]
$ docker build -t alanbchristie/pysimple:2019.6 .
$ docker push alanbchristie/pysimple:2019.6

Here my Docker account is alanbchristie and the repository there is pysimple. We're giving this image the tag 2019.6.

Tags are handled very differently in Docker, it does not understand that 1 is better than 2 - they're just strings that happen to also be numbers.

With the Docker image pushed we can now pull the application onto any Docker-enabled machine and run it with the command: -

$ docker run -d -p 4000:8080 alanbchristie/pysimple:2019.6
Unable to find image 'alanbchristie/pysimple:2017.6' locally
2019.3: Pulling from alanbchristie/pysimple
[...]

Building for ARM (k3s)

To build and push an image for the ARM processor (suitable for a Raspberry-Pi Kubernetes/k3s deployment): -

$ docker build --build-arg from_image=arm32v7/python:3.10.1-alpine3.14 \
    -t alanbchristie/pysimple:arm32v7-latest .
$ docker push alanbchristie/pysimple:arm32v7-latest

Related repositories

The following related GitHub repositories might be of interest: -

  • The PySimple Ansible Galaxy Role
  • The PySimple Ansible Operator

Alan B. Christie
December 2021

"Buy Me A Coffee"

pysimple's People

Contributors

alanbchristie avatar pkkht avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.