Building a Docker Image from Dockerfile
- Lets create some application files, assuming we will be working with a Python application
- Create python app file
vim app.py
from flask import Flask app = Flask(__name__) @app.route('/') def counter(): return '0'
save the file
ESC + wq!
- Create python app dependency definition file
vim requirements.txt
Flask==0.12
save the file
ESC + wq!
- Create python app file
- Now lets create a Dockerfile for the python application
vim Dockerfile
FROM python:2.7-alpine RUN mkdir /app WORKDIR /app COPY requirements.txt requirements.txt RUN pip install -r requirements.txt COPY . . LABEL maintainer="WebMagic Informatica <info@13.233.215.83>" \ version="1.0" CMD flask run --host=0.0.0.0 --port=5000
save the file
ESC + wq!
- Build flask application docker image using
docker image build -t web1 .
- Inspect image
docker image inspect web1
- Tag image
docker image build -t web1:1.0 .
- Get list of docker images
docker image ls
- Remove the created image using
docker image rm web1:1.0
Tag:Docker