Skip to content

Feature Request: Sorting Keywords in Docker Compose Files #151

@Marly212

Description

@Marly212

I would like to request a new feature for the VS Code Docker extension that allows for automatic sorting of keywords in Docker Compose files.

Current Behavior

When copying and pasting Docker Compose configurations from various sources (e.g., GitHub repositories), the order of keywords within service definitions is often inconsistent. This inconsistency makes it challenging to quickly read and understand the configuration, especially when working with multiple services or comparing different Compose files.

Proposed Feature

Add an option to automatically sort the keywords within each service definition in a Docker Compose file. This feature would:

  1. Allow users to define a custom sorting order for keywords.
  2. Provide a default sorting order (e.g., image, container_name, environment, volumes, ports, etc.).
  3. Be accessible through a command in the Command Palette or a context menu option when editing Docker Compose files.

Example

Before sorting:

services:
  myapp:
    ports:
      - "8080:80"
    environment:
      - NODE_ENV=production
    image: myapp:latest
    container_name: myapp-container
    volumes:
      - ./data:/app/data`

After sorting (with a predefined order):

services:  
  myapp: 
    image: myapp:latest 
    container_name: myapp-container 
    environment: 
      - NODE_ENV=production 
    volumes: 
     - ./data:/app/data 
    ports: 
     - "8080:80"

Benefits

  • Improved readability and consistency across projects.
  • Easier comparison between different Docker Compose files.
  • Time-saving for developers who frequently work with Docker Compose configurations.

Implementation Suggestions

  • Add a new setting to specify the desired keyword order.
  • Implement the sorting logic within the extension.
  • Ensure the feature respects YAML comments and maintains the overall structure of the file.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions