简体   繁体   中英

How to run python fixture script during mongodb docker build?

I am setting up a mongodb container. My web application will run in another container. Somehow, while building the mongodb image, I need to run fixture script that will generate password hash for the default user and will be inserted into the mongodb. The fixture script is written in python and uses bcrypt to generate hash. I haven't found ways to run python script in the mongodb container. Am I doing it the right way or are there any other better ways to achieve this.

The mongodb container likely doesn't have python installed -- in general, containers have the minimal amount of dependencies needed to accomplish their goal.

I think you have a couple options here:

  1. You can install python on to the container as part of your install process & then run the script (I wouldn't do this)
  2. You can pregenerate the fixture password hashes. The hash for a password won't change over time, so you should be able to create your fixture files before importing
  3. You can have another container (like your webserver or a third container) be set up to import fixtures. https://hub.docker.com/_/python/ could be an OK starting point

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM