【问题标题】:Dockerize Angular app which uses Python and Oracle as backendDockerize Angular 应用程序,它使用 Python 和 Oracle 作为后端
【发布时间】:2021-03-03 02:15:27
【问题描述】:

我正在尝试对我的 Angular 应用程序进行 dockerize,该应用程序从我的 python 应用程序调用后端数据库 Oracle。如果没有 docker,我可以在端口 4201 上为我的应用程序提供服务,而我的后端在端口 2232 上运行。所有这些都可以正常工作,但是当我尝试对其进行文档化时,我似乎得到了 COR 的错误。我不确定我错过了什么。

Python dockerfile:

FROM python:3
COPY requirements.txt ./
RUN pip install --no-cache-dir -r requirements.txt
ADD thomas.py /
CMD [ "python3", "./thomas.py" ]

Angular Dockerfile:

# Stage 1
FROM node:12.16.1-alpine as build-step
WORKDIR /usr/src/app
COPY package.json package-lock.json ./
RUN npm install
COPY . .
RUN npm run build --prod
# Stage 2
FROM nginx:1.17.1-alpine
COPY nginx.conf /etc/nginx/nginx.conf
COPY --from=build-step /usr/src/app/dist/bim-angulardashboard/ /usr/share/nginx/html

Nginx.conf 文件:

worker_processes 1;

events { worker_connections 1024; }

http {

    sendfile on;

    gzip              on;
    gzip_http_version 1.0;
    gzip_proxied      any;
    gzip_min_length   500;
    gzip_disable      "MSIE [1-6]\.";
    gzip_types        text/plain text/xml text/css
                      text/comma-separated-values
                      text/javascript
                      application/x-javascript
                      application/atom+xml;


    # Configuration for the server
    server {
        listen 80;
        server_name localhost;

      location / {
          root   /usr/share/nginx/html;
          index  index.html;
          expires -1;
          default_type application/javascript;
          add_header Pragma "no-cache";
          add_header Cache-Control "no-store, no-cache, must-revalidate, post-check=0, pre-check=0";
          try_files $uri$args $uri$args/ $uri $uri/ /index.html =404;
      }

      location /api {
            proxy_pass          http://<my_vm_server_name>:5000;
            proxy_set_header        Host $host;
      }
    }
}

Docker-compose.yml 文件:

version: '3'
services:
  python-app:
    build:
      context: ./docker/flask
      dockerfile: Dockerfile #this is your dockerfile
    container_name: python-app #docker container name
    restart: unless-stopped
    tty: true
    environment:
      SERVICE_NAME: app
      SERVICE_TAGS: dev
    working_dir: /
    ports:
      - "5000:5000" #binding ports, external port : application listening port
    volumes:
      - ./in000031-batch_dashboard/docker/flask/:/var/www/html # after : its the location in the container OS
    networks:
      app-network:
        ipv4_address: 172.20.0.2
  angular-app:
    build:
      context: .
      dockerfile: Dockerfile #this is your dockerfile
    container_name: angular-app #docker container name
    restart: unless-stopped
    tty: true
    environment:
      SERVICE_NAME: app
      SERVICE_TAGS: dev
    working_dir: /
    ports:
      - "4201:80" #binding ports, external port : nginx listening port
    volumes:
      - ./in000031-batch_dashboard/:/var/www/html # after : its the location in the container OS
    networks:
      app-network:
        ipv4_address: 172.20.0.3
  

#Docker Networks
networks:
  app-network:
    driver: bridge
    ipam:
      driver: default
      config:
          - subnet: 172.20.0.0/16
#Volumes
volumes:
  dbdata:
    driver: local  

如果我的任何配置文件有误,或者您有更好的解决方案,请告诉我?任何帮助,将不胜感激。谢谢

【问题讨论】:

  • 您是否在 docker 映像中安装了连接到 oracle db 所需的驱动程序?您是否按照堆栈跟踪末尾给出的站点中列出的步骤进行操作?
  • 我会将您的问题编辑为 a)反映堆栈跟踪中显示的错误(Oracle DB 连接错误)并将堆栈跟踪添加为代码 sn-p 而不是图像或 b)显示您看到的 CORS 错误的错误详细信息
  • 错误说你缺少一个库......你的问题没有提到任何关于 oracle 库的内容。我们不知道您做了什么或检查了什么,您必须将其包含在您的问题中。
  • @C.Nivs ,我现在添加了 COR 的错误截图。是的,我已经在我正在使用的 Linux VM 上安装了 Oracle_cx 的必要驱动程序。如果没有 docker,它会连接到 db,我会看到输出,但是在 docker 上运行它会出现上述错误。
  • 在谷歌上的第一次尝试向我展示了这个:blogs.oracle.com/opal/…

标签: python angular docker nginx docker-compose


【解决方案1】:

看起来 Python 和 Oracle DB 存在连接问题。 Oracle db 是如何安装的?它也是 docker 服务还是托管在其他地方?

确保为数据库连接提供正确的 Oracle db/ip 地址服务名称。

【讨论】:

  • 没有 docker 我使用link 中的步骤安装 Oracle_cx 并且我能够正常运行我的应用程序。但是当我在 docker 上运行它时,我应该在启动容器之前再次在 docker 上安装 Oracle_cx 吗?
猜你喜欢
  • 2020-01-01
  • 2021-01-01
  • 2021-06-18
  • 1970-01-01
  • 2020-07-14
  • 1970-01-01
  • 1970-01-01
  • 2022-01-11
  • 1970-01-01
相关资源
最近更新 更多