How Container Images Help Developers

0
2384

Containers offer a convenient way of developing and testing an application. This article gives some basic examples of how this can be done.

Getting infra for application development, deployment and testing is always a painful task for developers. Container images can reduce the time, effort, and complexity of this entire process. Images can be pulled from public or private repositories using Docker or Podman. Let’s take a close look at some basic examples.

For Python developers
Pull the image on your host with Python pre-installed:

docker pull docker.io/python

This will take you into the Python shell:

docker run -it docker.io/python
Python 3.9.0 (default, Oct 13 2020, 20:14:06)
[GCC 8.3.0] on linux
Type “help”, “copyright”, “credits” or “license” for more information.
>>>

Let’s take a look at how a developer creates a customised image using Dockerfile. In the example below, I am referring to the Python flask application called app.py created by one of the developers. This is being hosted on a container:

Figure 1: Docker container cycle
FROM python:3.7-alpine
WORKDIR /code
ENV FLASK_APP=app.py
ENV FLASK_RUN_HOST=0.0.0.0
RUN apk add --no-cache gcc musl-dev linux-headers
RUN pip install flask
RUN pip install redis
EXPOSE 5000
COPY . .
CMD [“flask”, “run”]

To build the image, you can use:

docker build -t myapp

Once the above image is built, it will have app.py as a flask application on a container. Whenever the application version or code has to be updated, simply build it again and push it to a private or public registry.

LEAVE A REPLY

Please enter your comment!
Please enter your name here