Skip to content

Commit

Permalink
Merge pull request devopshobbies#55 from AliMehraji/main
Browse files Browse the repository at this point in the history
Update: Reduce Layers in dockerfile in Django
  • Loading branch information
mehdi-ra authored Aug 9, 2023
2 parents 9c2b1cb + 73ea0ad commit d009d5e
Show file tree
Hide file tree
Showing 5 changed files with 35 additions and 31 deletions.
8 changes: 4 additions & 4 deletions 07-Python/python-django/Django
Original file line number Diff line number Diff line change
Expand Up @@ -10,10 +10,10 @@ WORKDIR /app
COPY . /app

# Installing requirements
ADD requirements/req.txt /app
RUN pip3 install --upgrade pip
RUN pip3 install -r req.txt
RUN pip3 install django gunicorn
COPY requirements/req.txt /app
RUN pip3 install --no-cache-dir pip && \
pip3 install -r req.txt && \
pip3 install django gunicorn


# Collect static files
Expand Down
6 changes: 3 additions & 3 deletions 07-Python/python-with-postgresql/README.md
Original file line number Diff line number Diff line change
@@ -1,12 +1,12 @@
# Python With PostgreSQL

## Introduction
This dockercompose file creates a python application server alongside a PostgreSQL server and pgadmin server as database management tool
This docker-compose file creates a python application server alongside a PostgreSQL server and pgadmin server as database management tool

## How to use
You can simply use project folder as your project main folder and this docker file updates Python project and run your new code everytime you restart python container
You can simply use project folder as your project main folder and this docker file updates Python project and run your new code every time you restart python container

## Required information
You can access to postgreSQL username and password inside dockercompose.yaml file.
You can access to postgreSQL username and password inside docker-compose.yaml file.

Enjoy!
39 changes: 21 additions & 18 deletions 13-FastApi/README.md
Original file line number Diff line number Diff line change
@@ -1,45 +1,48 @@
![Docker](https://img.shields.io/badge/docker-%230db7ed.svg?style=for-the-badge&logo=docker&logoColor=white)
![FastAPI](https://img.shields.io/badge/FastAPI-005571?style=for-the-badge&logo=fastapi)
# Learning Dockerfile for Beginners

# Dockerfile for Beginners

This project contains a simple and practical example of a Dockerfile to help beginners learn how to use Docker.

## Prerequisites

- Docker installed on your system
- Basic knowledge of the Linux command line
- Docker installed on your OS. [Docker Installation](https://docs.docker.com/engine/install/)
- Basic knowledge of the Linux command line.

## Here's what each line does
## Each Line Explanation in Dockerfile

- ``FROM tiangolo/uvicorn-gunicorn-fastapi:python3.9-slim``: Use the official fastapi image as our base image. We're using the slim version to keep the image small.

- ``WORKDIR /app``: Set the working directory in the container to /app.

- ``COPY requirements.txt .``: Copy the requierments file from the current directory to the container.
- ``WORKDIR /app``: Set the working directory in the container to `/app`.

- ``COPY requirements.txt .``: Copy the `requirements.txt` file from the current directory to the container which is `/app` directory, because in the previous step we have used `WORKDIR` this directive makes `/app` directory and goes in it.

- ``RUN pip install --no-cache-dir -r requirements.txt``: Install the project dependencies using pip.

- ``COPY main.py .``: Copy the rest of the application code to the container.
- ``COPY main.py .``: Copy the rest of the application code to the container which is `/app`

- ``CMD ["uvicorn", "main:app", "--host", "0.0.0.0", "--port", "80"]``: Set the command to start the application.

## Usage

1. Clone the repository:

```sh
git clone https://github.com/devopshobbies/docker-templates.git
```
```sh
git clone https://github.com/devopshobbies/docker-templates.git
```

2. Build the Docker image:

```sh
cd docker-templates/12-FastApi
docker build -t hello-fastapi .
```
```sh
cd docker-templates/13-FastApi
docker build -t hello-fastapi .
```

3. Run the Docker container:

```sh
docker container run -d hello-fastapi -p 80:80
```
```sh
docker container run --detach --publish 80:80 hello-fastapi
```
> -d,--detach &emsp;&emsp;&emsp;&emsp; Run container in background and print container ID </br>
> -p, --publish list &emsp;&emsp; Publish a container's port(s) to the host
1 change: 1 addition & 0 deletions nginx/Dockerfile
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
FROM nginx:1.23

LABEL MAINTAINER="AMIRAJOODANI | https://nextsysadmin.ir"

COPY nginx.conf /etc/nginx/conf.d/default.conf
Expand Down
12 changes: 6 additions & 6 deletions nginx/nginx.conf
Original file line number Diff line number Diff line change
Expand Up @@ -5,20 +5,20 @@ upstream app {

server {
listen 80;
server_name localhost;
charset utf-8;

access_log /var/log/nginx/access.log;
error_log /var/log/nginx/error.log;

root /usr/share/nginx/html;
index index.html index.htm;
root /usr/share/nginx/html;
index index.html index.htm;

location / {
# proxy the request to the upstream
proxy_pass http://app;
proxy_pass http://app;
proxy_redirect off;
proxy_set_header Host $host;
}

}

location /app/static/ {
alias /logapp/static/;
Expand Down

0 comments on commit d009d5e

Please sign in to comment.