Giter Club home page Giter Club logo

docker_containerize's Introduction

DOCKER - Containerize Python applications


This project uses docker to containerize a IMDB move scraper application

STEPS:

  1. 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

alt text 2) Create docker image:

  • specify base image FROM
  • ADD python file
  • install dependencies - RUN
  • CMD to run python main.py in docker terminal*
  1. Creates docker image:
  • docker build -t dockerfun .
  • pulls python image, adds main.py, then install modules

alt text 4) Start container

  • docker run -t -i dockerfun * (-i = gives sudo terminal / -i - puts in interactive mode since there is user input requested)

Project 2: FAST-API

  1. Create new dir
  2. create virtual environment
  3. install dependencies
    • pip install fastapi
    • pip install uvicorn (web server)
  4. run python script
  5. web browser shows server is running

DOCKERIZE APPLICATION

  1. pip freeze > requirements.txt

writes all dependencies into file

  1. Create docker file in root folder
  2. 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

alt text

  1. rebuild image :

docker build -t python-fastapi . docker run -p 8000:8000 python-fastapi docker

  1. Check docker hub can see container
  2. In terminal, 'docker ps' shows running docker containers
  3. Can access docker container terminal in docker hub or in terminal --

docker_containerize's People

Contributors

chaseryder08 avatar

Watchers

 avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.