Long story short I need to extend apache/couchdb/ Dockerfile so that would do some magic processing to get 2 values (username and password) and then start the couchdb instance with an admin.
Normally you would do it by running docker run ... -e COUCHDB_USER=admin -e COUCHDB_PASSWORD=password couchdb but I may not know the values beforehand and I want those to be retrieve from somewhere every time container is starting.
I made a Dockerfile that looks more or less like this:
FROM couchdb:2.1.1
RUN apt-get update --force-yes && apt-get install -y python3
RUN curl https://bootstrap.pypa.io/get-pip.py | python3
ADD . /app
RUN pip install -r /app/requirements.txt
CMD ["python3", "/app/start_couch.py"]
Where start_couch.py looks like this:
import os
import subprocess
user,password = very_complex_stuff()
os.environ['COUCHDB_USER'] = user
os.environ['COUCHDB_PASSWORD'] = password
subprocess.call(["/opt/couchdb/bin/couchdb"], env=os.environ)
yet when build and run my image the couchdb starts without an pre-set admin (I mean i can do everything without login)
Can someone point out what am i doing wrong or suggest a different solution?
The criteria is that admin credentials are taken from a python script (function) and it needs to executed on docker run
Mistery solved
that image have a custom entrypoint ENTRYPOINT ["tini", "--", "/docker-entrypoint.sh"], so the -e switch sets up env vars before the .sh is execute however my python script is run later.
I fix this by changing adding to Dockerfile
ENTRYPOINT ["tini", "--"]
CMD ["python3", "/app/start_couch.py"]
and calling couch from python like this:
subprocess.call(
["/docker-entrypoint.sh", "/opt/couchdb/bin/couchdb"],
env=os.environ
)
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With