Docker Compose failing at second container

Viewed 21

I have this code:

module_a:

import pandas as pd


csv = 'customers.csv'
df_customers = pd.read_csv(csv, sep=';')

csv2 = 'payments.csv'
df_payments = pd.read_csv(csv2, sep=';')

df_customers = df_customers.merge(df_payments)
df_customers = df_customers.reindex(columns=('id_customer', 'job', 'date','payment'))
df_customers = df_customers.groupby(by=['id_customer','date']).agg({'job': 'max', 'payment':'max'})
df_customers = df_customers.reset_index()

Then the Dockerfile:

FROM python:3.10
WORKDIR /usr/src/app
RUN pip install pandas
COPY . .
CMD ["python", "./main.py"]

Next, module_b:

from pathlib import Path
import numpy as np

conditions = [
    (df_customers['date'] == '2021-11-30') & (df_customers['payment'] > 10000),
    (df_customers['job'] == 'management') |(df_customers['job'] == 'admin'),
    (df_customers['date'] == '2021-11-30') & (df_customers['payment'] > 5000),
    (df_customers['job'] == 'blue-collar') | (df_customers['job'] == 'technician')
    | (df_customers['job'] == 'entrepreneur')
]
values = [30,30,20,20]

df_customers['discount'] = np.select(conditions,values)
df_customers = df_customers.loc[(df_customers[['discount']] != 0).all(axis=1)]
df_customers = df_customers.reindex(columns=['id_customer','discount'])
df_customers.to_csv(r'C:\Users\juanm\OneDrive\Escritorio\Python\Challenge\Resolucion\output_folder\output_2021-31-12.csv', index = False, header=True,dtype=str)

Then its Dockerfile:

FROM python:3.10
WORKDIR /usr/src/app
ADD main.py .
RUN pip install pandas pathlib numpy
CMD ["python", "./main.py"]

Finally, the docker-compose.yml:

version: "4.11"
services:
  moodule_a:
    build: C:\Users\juanm\OneDrive\Escritorio\Python\Challenge\Resolucion\module_a
  module_b:
     build: C:\Users\juanm\OneDrive\Escritorio\Python\Challenge\Resolucion\module_b
networks:
  default:
    external:
      name: some-net

I need to run both containers with compose, but, when I try docker compose up, I receive this error:

module_a-module_b-1   | NameError: name 'df_customers' is not defined

What I am doing wrong? I've searched everywhere without any luck.

0 Answers
Related