Skip to content

Instantly share code, notes, and snippets.

@iKunalChhabra
Created September 26, 2022 12:06
Show Gist options
  • Save iKunalChhabra/d4f7f322dba7b45ec0fe54b6f1762ed3 to your computer and use it in GitHub Desktop.
Save iKunalChhabra/d4f7f322dba7b45ec0fe54b6f1762ed3 to your computer and use it in GitHub Desktop.
Python script to fetch password variables from inside docker container
import docker
# connect to docker client
client = docker.from_env()
# execute command to get env_list variables
output = client.containers.run(image="ikunalchhabra/airflow-datascience:latest",
command="printenv",
remove=True)
# get list of env_list variables
env_list = output.decode("utf-8").strip().split("\n")
# convert list of env_list variables to dictionary
env_dict = dict(e.split("=") for e in env_list)
# search for env_list variable keys that contain "password"
passwords = {key: value for key, value in env_dict.items()
if "password" in key.lower()}
# print passwords
print(passwords)
# output
# {'AIRFLOW_PASSWORD': 'admin'}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment