Home>

There are three containers connected viadocker-compose

version: "3"
services:
  app:
    container_name: tester
    build:
      context: .
    depends_on:
      -pgadmin
  postgres:
    image:postgres:13
    container_name: postgres
    environment:
      -POSTGRES_DB=ny_taxi
      -POSTGRES_USER=root
      -POSTGRES_PASSWORD=root
      -POSTGRES_HOST_AUTH_METHOD=trust # allow all connections without a password. This is *not* recommended for prod
    volumes:
      -c:/data_talks_club/ny_taxi_postgres_data:/var/lib/postgresql/data/# persist data even if container shuts down
    ports:
      -"5432:5432"
  pgadmin:
    image:dpage/pgadmin4
    container_name: pgadmin
    environment:
      [email protected]
      -PGADMIN_DEFAULT_PASSWORD=root
      -PGADMIN_LISTEN_PORT=5050
    ports:
      -"5050:5050"
volumes:
  database-data:

YesDockerfilewhich contains a python script that takes parameters as input.

FROM python:3.9.1
RUN apt-get -y update
RUN apt-get -y install wget
RUN apt-get install python3-psycopg2
RUN pip install pandas sqlalchemy psycopg2
WORKDIR /csv_uploader
COPY upload-data.py upload-data.py
ENTRYPOINT [ "python", "upload-data.py" ]

It starts like this

upload-data.py --login=root --password=ppp

How to run this script?

ps. InitiallypostgresandpgadminI ran together as wellDockerfileseparately. FromDockerfilethere was no access to the database because in different networks, so I decided to combine them into one compose.

I built the Dockerfile

docker build -t taxi_uploader:v001 .

and pass parameters to it

docker run taxi_uploader:v001 --login=root --password=root
  • Answer # 1

    If --login and --password will never change since the build, then specify them in the instruction ENTRYPOINT.

    If you want to be able to change these options without rebuilding, put them in environment variablesapp service, and read them in the script.

  • Answer # 2

    If --login and --password will never change since the build, then specify them in the instruction ENTRYPOINT.

    If you want to be able to change these options without rebuilding, put them in environment variablesapp service, and read them in the script.