Step 1: Download and install docker
Step 2: Install image
–This will update existing version or install from scratch
$brew install docker
Step 3: Build docker image
Create following three files in empty folder.
File Name: cacl.py
a = sys.argv
b = sys.argv
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
# Set the working directory to /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
# 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 .
We should be able to see calc image
>docker run -p calc 2 3
sum is 5
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.