![]() Using these techniques, you can simplify your Docker Compose configuration and manage all your services in just one file. Now you will have three running services: nginx, redis_c, and nginx_b. env file: # docker-compose.yml version: '3' services: nginx_b: image: nginx:latest container_name: nginx_b ports: - "82:80" - "2443:443" env_file:. Then, add another service to the common.yml file: # common.yml version: '3' services: nginx_a: image: nginx:latest container_name: nginx_a ports: - 81:80 - 1443:443 redis_c: image: redis:latest container_name: redis_c ports: - "6381:6380"įinally, load all the services in the docker-compose.yml file using the. env COMPOSE_PATH_SEPARATOR=: COMPOSE_FILE=common.yml:docker-compose.yml env files that allows you to load all the services in the docker-compose file without even mentioning them. ![]() This will give you two running services: nginx and nginx_b. Next, create a docker-compose.yml file that includes the common.yml file and its own service as well: # docker-compose.yml services: nginx: extends: file: common.yml service: nginx_a nginx_b: image: nginx:latest container_name: nginx_b volumes: ports: - 82:80 - 2443:443 However, this solution is not necessarily an anti-pattern, but it does raise some design concerns which I will discuss in the last section of this document.įirst, define a common.yml file: # common.yml version: '3' services: nginx_a: image: nginx:latest container_name: nginx ports: - "81:80" - "1443:443" This is because the extends option can introduce complexity and make it more difficult to manage your Docker Compose configuration. Please note that while the extends option in Docker Compose is a convenient way to include services from other files, it is not recommended by Docker. docker-compose -f common.yml -f app.yml up 2. Next, with -f option you will able to call each service files and its dependent services easily. command: python manage.py runserver 0.0.0.0:8000 volumes:. # app.yml version: '3' services: web: build. Then, create separated file for other services or apps. ![]() # common.yml version: '3' services: db: image: postgres:11-alpine restart: always environment: POSTGRES_PASSWORD: example POSTGRES_USER: example POSTGRES_DB: example To address this, you can create a common.yml file that includes the services and configurations needed for all your services. This can result in complexity when provisioning and combining files in the beginning. ![]() The Docker solution provides a simpler way to establish connections between Docker files, but it does not follow any logical or object-oriented programming (OOP) principles for extending. Multiple file call (Docker recommendation) However, for those working with legacy projects or in situations where this approach isn’t possible, I’ll discuss how to make it work. This opened up a lot of possibilities and best practices for managing Docker Compose configurations in a modular way. Back in 2019, when Docker Compose version 2 was still in use, I suggested a way to manage complex and inherited Docker Compose structures in response to a question about importing one Docker Compose file into another. ![]()
0 Comments
Leave a Reply. |
AuthorWrite something about yourself. No need to be fancy, just an overview. ArchivesCategories |