Reputation: 616
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
Upvotes: 3
Views: 679
Reputation: 616
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
)
Upvotes: 2
Reputation: 7952
... couchdb starts without a pre-set admin (I mean i can do everything without login) ...
That's called The Admin Party which is the default configuration if you don't modify the security configurations of CouchDB. It will start to make sense if you take a look at the documentation.
Upvotes: 0