Docker Compose: Difference between revisions

From bibbleWiki
Jump to navigation Jump to search
 
(8 intermediate revisions by the same user not shown)
Line 22: Line 22:
==Introduction==
==Introduction==
Django is a python based web framework solution. To create this container we will
Django is a python based web framework solution. To create this container we will
*define the python requirement document
*Define the python requirement document
*define a docker file
*Define a docker file
*define a docker compose stack file
*Define a docker compose stack file


=Django Container=
==Define the python requirement document==
==Requirements==
Here are the specific requirements for the Django.
Here are the specific requirements for the Django cotainer.
<syntaxhighlight lang="bash">
<syntaxhighlight lang="bash">
Django==3.1.5
Django==3.1.5
Line 37: Line 36:
pika==1.1.0
pika==1.1.0
</syntaxhighlight>
</syntaxhighlight>
==DockerFile==
==Define a docker file==
This command runs the django app at start up
This defines the App code for the django DockerFile
<syntaxhighlight lang="Dockerfile">
<syntaxhighlight lang="Dockerfile">
FROM python:3.9
FROM python:3.9
Line 47: Line 46:
COPY . /app
COPY . /app
</syntaxhighlight>
</syntaxhighlight>
==Yaml==
 
We can build a container using docker-compose. Create a docker file with
==Define a docker compose stack file==
<syntaxhighlight lang="Dockerfile">
We define the deployment include, services, database and networks
<syntaxhighlight lang="yaml">
version: '3.8'
version: '3.8'
services:  
services:  
Line 100: Line 100:
     external: true
     external: true
</syntaxhighlight>
</syntaxhighlight>
=Flask Container=
=Flask Container=
==Requirements==
==Introduction==
Here are the specific requirements for the Flask container.
Flask is a python based web framework solution. To create this container we will
*Define the python requirement document
*Define a docker file
*Define a docker compose stack file
==Define the python requirement document==
Here are the specific requirements for the Flask.
<syntaxhighlight lang="bash">
<syntaxhighlight lang="bash">
Flask==1.1.2
Flask==1.1.2
Line 114: Line 120:
pika==1.1.0
pika==1.1.0
</syntaxhighlight>
</syntaxhighlight>
==DockerFile==
 
This command runs the flask app at start up
==Define a docker file==
This defines the App code for the Flask DockerFile
<syntaxhighlight lang="Dockerfile">
<syntaxhighlight lang="Dockerfile">
FROM python:3.9
FROM python:3.9
Line 124: Line 131:
COPY . /app
COPY . /app
</syntaxhighlight>
</syntaxhighlight>
==Yaml==
 
We can build a container using docker-compose. Create a docker file with
==Define a docker compose stack file==
<syntaxhighlight lang="Dockerfile">
We define the deployment include, services, database and networks
<syntaxhighlight lang="yaml">
version: '3.8'
version: '3.8'
services:  
services:  

Latest revision as of 20:29, 16 August 2021

Docker Compose

Compose is a tool for defining and running multi-container Docker applications. With Compose, you use a YAML file to configure your application’s services. Then, with a single command, you create and start all the services from your configuration.

Example of MYSQL Container

This is an example of a mysql. The ports are changed to stop collision with desktop.

version: '3.8'
networks:
  default:
services:
   db:
     image: mysql:5.7
     container_name: conference_security
     ports:
       - 3307:3306
     volumes:
       - "./.data/db:/var/lib/mysql"
     environment:
       MYSQL_ROOT_PASSWORD: pass
       MYSQL_DATABASE: TEST_DB

Example of django Container

Introduction

Django is a python based web framework solution. To create this container we will

  • Define the python requirement document
  • Define a docker file
  • Define a docker compose stack file

Define the python requirement document

Here are the specific requirements for the Django.

Django==3.1.5
djangorestframework==3.12.2
mysqlclient==2.0.3
django-mysql==3.10.0
django-cors-headers==3.6.0
pika==1.1.0

Define a docker file

This defines the App code for the django DockerFile

FROM python:3.9
ENV  PYTHONNUMBUFFERED 1
WORKDIR /app
COPY requirements.txt /app/requirements.txt
RUN pip install -r requirements.txt
COPY . /app

Define a docker compose stack file

We define the deployment include, services, database and networks

version: '3.8'
services: 
  django:
    container_name: djangoapp
    build: 
      context: .
      dockerfile: Dockerfile
    command: 'python3 manage.py runserver 0.0.0.0:8000'
    ports: 
      - 8000:8000
    volumes: 
      - .:/app
    depends_on:
      - db
    networks:
      django_demo:

  queue:
    environment:
      - PYTHONUNBUFFERED=1
    build: 
      context: .
      dockerfile: Dockerfile
    container_name: djangoqueue
    command: 'python3 consumer.py'
    depends_on:
      - db
    networks:
      django_demo:

  db: 
    image: mysql:5.7.32
    container_name: djangodb
    restart: always
    environment: 
      MYSQL_DATABASE: admin
      MYSQL_USER: root
      MYSQL_PASSWORD: root
      MYSQL_ROOT_PASSWORD: root
    volumes: 
      - .dbdata:/var/lib/mysql
    ports: 
      - 33066:3306
    networks:
      django_demo:

networks:
  django_demo:
    external: true

Flask Container

Introduction

Flask is a python based web framework solution. To create this container we will

  • Define the python requirement document
  • Define a docker file
  • Define a docker compose stack file

Define the python requirement document

Here are the specific requirements for the Flask.

Flask==1.1.2
Flask-SQLAlchemy==2.4.4
SQLAlchemy==1.3.20
Flask-Migrate==2.5.3
Flask-Script==2.0.6
Flask-Cors==3.0.9
requests==2.25.0
mysqlclient==2.0.3
pika==1.1.0

Define a docker file

This defines the App code for the Flask DockerFile

FROM python:3.9
ENV  PYTHONNUMBUFFERED 1
WORKDIR /app
COPY requirements.txt /app/requirements.txt
RUN pip install -r requirements.txt
COPY . /app

Define a docker compose stack file

We define the deployment include, services, database and networks

version: '3.8'
services: 
  flask:
    build: 
      context: .
      dockerfile: Dockerfile
    container_name: flaskapp
    command: python main.py
    ports: 
      - 8001:5000
    volumes: 
      - .:/app
    depends_on:
      - db
    networks:
      django_demo:

  queue:
    build: 
      context: .
      dockerfile: Dockerfile
    container_name: flaskqueue
    command: 'python consumer.py'
    depends_on:
      - db
    networks:
      django_demo:

  db: 
    image: mysql:5.7.32
    container_name: flaskdb
    restart: always
    environment: 
      MYSQL_DATABASE: main
      MYSQL_USER: root
      MYSQL_PASSWORD: root
      MYSQL_ROOT_PASSWORD: root
    volumes: 
      - .dbdata:/var/lib/nysql
    ports: 
      - 33067:3306
    networks:
      django_demo:

networks:
  django_demo:
    external: true