Created simple flask with application then containers application in Docker container image and create a docker repository.
- Create virtual environment
virtualenv env_name
env_name = virtual environment name.
- Create requirements.txt file
Requirements files serve as a list of items to be installed by pip
- intall flask
pip install Flask
- Create app.py file
app.py : this file store application route and entry point of application
- create a docker file (Dockerfile)
Dockerfile : A Dockerfile is a text document that contains all the commands a user could call on the command line to assemble an image
command :
FROM
COPY
WORKDIR
RUN
CMD
```
2. create a docker image
```bash
docker build -t flask-helloworld .
flask-helloworld >> docker image name
- run docker image as a container
docker run -p 5000:5000 flask-helloworld
(5000:5000 > host port:container port)
- docker login in docker hub
docker login
- docker image name should be with your docker user name (kaushalpandey/flask-helloworld) 2.1 rename docker image first method
docker image rm -f flask-helloworld
(remove old docker image)
docker build -t kaushalpandey/flask-helloworld .
(again create new docker image)
2.2 rename docker image second method
docker tag flask-helloworld kaushalpandey/flask-helloworld
(old name) (new name)
- push to docker hub
docker push kaushalpandey/flask-helloworld:latest