Docker Community Forums

Share and learn in the Docker community.

Docker compose help - running python

Hello

I’m trying to use a docker container to run my python which uses psycopg2 library:

my dockerfile is like below:
###########################################
FROM postgres:latest

install Python 3

RUN apt-get update

RUN apt-get update && apt-get install -y python3 python3-pip

RUN apt-get -y install python3.7-dev

install postgresql packages

RUN apt-get install --fix-missing postgresql-client-10

RUN apt-get install --fix-missing libpq-dev -y

RUN apt-get install --fix-missing gcc -y

RUN apt-get install --fix-missing musl-dev -y

#install dependencies

RUN apt install curl -y

RUN apt install unzip -y

install psycopg2 library with PIP

RUN pip3 install psycopg2

RUN pip3 install boto3

install aws cli

RUN curl “https://awscli.amazonaws.com/awscli-exe-linux-x86_64.zip” -o “awscliv2.zip”

RUN unzip awscliv2.zip

RUN ./aws/install

RUN mkdir /app

WORKDIR /app

COPY . .

ENTRYPOINT [“python3.7 /app/src/generateLedgerBatch.py -d {BUCKET} -p {PREFIX} -r {ROWS} -b {BATCHSIZE} -f {FILES} -s {STARTFILE} -e ${ENDFILE}”]

#######################

I’m passing environment variables in “config.properties”.

Below is my docker-compose:

##############################
version: ‘3’

services:

ledgergenerator:
build: ./ledger-generator
container_name: ledger-generator
env_file:
- ‘config.properties’
#image: 134635467856.dkr.ecr.us-east-1.amazonaws.com/hive-stat-web:hivescanner-0.1
restart: always
ports:
- ‘5432:5432’
volumes:
- ./ledger-generator:/app
- $PWD/logs:/app/logs
- $PWD/ledgerbatchfiles:/app/ledgerbatchfiles
- $PWD/pg-data/:/var/lib/postgresql/data
- $PWD/python-app:/var/www/html

##############################

my folder stucture:

When I run below command, I get error:

docker-compose up --build -d

Error:

ERROR: for ledgergenerator Cannot start service ledgergenerator: OCI runtime create failed: container_linux.go:349: starting container process caused "exec: “python3.7 /app/src/generateLedgerBatch.py -d {BUCKET} -p {PREFIX} -r {ROWS} -b {BATCHSIZE} -f {FILES} -s {STARTFILE} -e {ENDFILE}\": stat python3.7 /app/src/generateLedgerBatch.py -d {BUCKET} -p {PREFIX} -r {ROWS} -b {BATCHSIZE} -f {FILES} -s {STARTFILE} -e {ENDFILE}: no such file or directory”: unknown
ERROR: Encountered errors while bringing up the project.

How do I make my dockerfile run “generateLedgerBatch.py” file when run docker-compose file.

please help.

Thanks in advance,
Arun