This project uses docker to containerize a IMDB move scraper application
- Create main.py python script - this scrapes IMDB and suggests a movie from their website
-
Imported libraries:
- random, requests (HTML Parser),
- requests - allows you to send HTTP requests using Python.
- Beautiful soup - package to parse html/xml to extract data
- specify base image FROM
- ADD python file
- install dependencies - RUN
- CMD to run python main.py in docker terminal*
- Creates docker image:
- docker build -t dockerfun .
- pulls python image, adds main.py, then install modules
- docker run -t -i dockerfun * (-i = gives sudo terminal / -i - puts in interactive mode since there is user input requested)
- Create new dir
- create virtual environment
- install dependencies
- pip install fastapi
- pip install uvicorn (web server)
- run python script
- web browser shows server is running
- pip freeze > requirements.txt
writes all dependencies into file
- Create docker file in root folder
- Create docker container with all dependencies
docker build -t python-fastapi .
Issue is it doesn't work --
- when run container need to map port :
- docker run -p 8000:8000 python-fastapi (Map port 8000:8000)
- put in arguments in uvicorn.run(app, port=8000, host="0.0.0.0")
- Need to specify host address and port
- rebuild image :
docker build -t python-fastapi . docker run -p 8000:8000 python-fastapi
- Check docker hub can see container
- In terminal, 'docker ps' shows running docker containers
- Can access docker container terminal in docker hub or in terminal --