简体   繁体   中英

Best practices when copying source files with Docker

Lastly, I have been trying to improve my Docker skills, but there is something I'm still stuck when I have to deal with it. Let's say I have an application divided into modules, each of them being its own Docker service.

All modules use the config stored under config/config.ini, but this config needs some preprocessing so what they use is the functions of config/config.py.

I have implemented that as:

  • Each Dockerfile of each module COPY the contents of the config/ folder into their own ( COPY ./config . )
  • Each module imports the config functions with: from config import ###

This method does work, but it breaks the IDE as the config folder is not on the pythonpath so I lost some important functionality, and what is worse I don't think this is the cleanest way of achieving what I want.

Furthermore, this also happens with source files. Normally in my python development, I would have just created a package called "APP" (see the folder structure below) and then I could have imported any source file in any folder of the package, but because each subfolder is a different Docker service I cannot make this project a python package. For example, the tests are also dockerized so each test also copies the needed source files from other folders:

the file unit_test_main_module.py needs to test all the source files in main_module so it copies the files with the Dockerfile.

APP
 ├── unit_tests
     ├── Dockerfile
     └── unit_test_main_module.py
 ├── integration_tests
     ├── Dockerfile
     └── first_integration_test.py
 ├── config
     ├── config.ini
     └── config.py
 └── main_module
     ├── source_file_one.py
     └── source_file_two.py

Any advice?

I would suggest having one Dockerfile per process . A Docker image is basically a self-contained way to run a process. So if you only ever run one process, you only need one Dockerfile.

You might want, perhaps, a second Dockerfile for a testing image. But you don't need one per package.

Assuming two, one for main application and one for tests, it would be in top directory.

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