Member-only story
Fixing problem with Docker container not starting with docker build with --build-arg and Dockerfile having ARG
I was using GitHub Copilot Chat to generate a way to generate a Dockerfile that helps me to get started with PostgreSQL database on a container and I got this as a first run.
After making some adjustment to the SQL connection credential and creating create-data.sql file, I was able to run by creating image with the following command.
docker build -t custom-database-layer:1.0 .
Followed with the following command to launch as a Docker container:
docker run -p 5432:5432 — rm — detach — interactive — name custom-database-layer -d custom-database-layer:1.0
Then, I could check the database by connecting using PostgreSQL client in Visual Studio Code.
This works fine for a local database, but hard coding SQL connection in a file is no-no for any thing that needs to be shared in a remote environment.
Thus, I asked GitHub Copilot Chat:
What can I do if I want to replace database connection strings in Dockerfile with environment variables that can read from somewhere else?