Sign inSign up

ea1het/my_api

By ea1het

•Updated about 8 years ago

This is an example RESTful API microservice written in Python 3 and Flask

Image
0

136

ea1het/my_api repository overview

⁠Cloud Architecture basics

⁠PYTHON API RUNNING AS CONTAINER

⁠1. How to build a container image

Open a Terminal window (Mac, Linux) or CMD window (Windows) and place yourself in the directory where the source code of your project is. Then, type the following command:

docker build . -t my_api:v1

where:

  • "." represents the current directory where you are

  • "-t" means you want to tag your container image with name

  • "my_api" is the main name of your container image

  • "v1" is the part of the tag name related to the container version

⁠2. How to run a container image

Open a Terminal window (Mac, Linux) or CMD window (Windows) and type:

docker run -p 5000:5000 my_api:v1 -it api_container

where:

  • "my_api:v1" is the local image you want to run as a container

  • "api_container" is the name you want to assign to this container image when it is run.

⁠3. How to open a console inside a container

Open a Terminal window (Mac, Linux) or CMD window (Windows) and type:

docker exec -it <container_id> ash

NOTE: ash is the built-in shell in Alpine linux.

⁠4. Dockerfile

FROM alpine:3.8
MAINTAINER Jonathan Gonzalez <[email protected]> @EA1HET

RUN apk add --no-cache python3                                  \
    && python3 -m ensurepip                                     \
    && pip3 install -U pip                                      \
    && rm -rf /usr/lib/python*/ensurepip                        \
    && rm -rf /root/.cache                                      \
    && rm -rf /var/cache/apk/*                                  \
    && find /                                                   \
        \( -type d -a -name test -o -name tests \)              \
        -o \( -type f -a -name '*.pyc' -o -name '*.pyo' \)      \
        -exec rm -rf '{}' +                                     \
    && mkdir /app

EXPOSE 5000

WORKDIR /app
COPY . /app

RUN pip install --no-cache-dir -r requirements.txt

ENTRYPOINT /app/boot.sh

Tag summary

Content type

Image

Digest

Size

14 MB

Last updated

about 8 years ago

docker pull ea1het/my_api:v1