Build Docker Container

Step 1: Download and install docker
https://www.docker.com/community-edition
110MB File

Step 2: Install image

$docker version

–This will update existing version or install from scratch
$brew install docker

Step 3: Build docker image
https://docs.docker.com/get-started/part2/#build-the-app

https://en.wikipedia.org/wiki/Flask_(web_framework)

Create following three files in empty folder.
——————
File Name: cacl.py

import sys
a = sys.argv[1]
b = sys.argv[2]
summ = int(a) + int(b)
print "sum is", summ

——————
File Name: Dockerfile

# Use an official Python runtime as a base image. Get this version from local system with >python –version
FROM python:2.7.10

# Set the working directory to /app
WORKDIR /app

# Copy the current directory contents into the container at /app
ADD . /app

# Install any needed packages specified in requirements.txt. These are packages used in python script.
RUN pip install -r requirements.txt

# Make port 80 available to the world outside this container
EXPOSE 80

# Define environment variable
ENV NAME calc

# Run calc.py when the container launches
ENTRYPOINT [“python”, “calc.py”]

——————
File Name: requirements.txt (empty)

——————

>docker build -t calc .

>docker images
We should be able to see calc image

>docker run -p  calc 2 3
sum is 5

-o-

Problems:
This is first simple docker image with Python code.
Every time we run, it creates image from cache and executes and dies.
Leaving many unused images, accumulating space.
>docker ps -a

We can see all past images, which are not existed.

Leave a comment

This site uses Akismet to reduce spam. Learn how your comment data is processed.