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:
YesDockerfile
which 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.
Initiallypostgres
andpgadmin
I ran together as wellDockerfile
separately. FromDockerfile
there 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
-
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.
Related questions
- linux : Connecting via ssh when building using Jenkins
- sqlite : docker error: bind source path does not exist
- docker : How to send a command to restart another container from a Decker container?
- postgresql : I get the error "(psycopg2.OperationalError) FATAL: role "wsb" does not exist", but the user does exits
- Can't connect to kafka from docker container
- c# : Unable to save data changed in the program in docker volumes
- sqlite data not saved to docker volume
- docker-compose -port not available in container
- git : Issue with dockerfile during deployment: lstat /home/Dockerfile: no such file or directory
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.