Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Incompatibility with Docker Compose V2 (Plugin version) #4

Closed
damien-mathieu1 opened this issue Feb 3, 2025 · 3 comments
Closed

Incompatibility with Docker Compose V2 (Plugin version) #4

damien-mathieu1 opened this issue Feb 3, 2025 · 3 comments
Labels
enhancement New feature or request

Comments

@damien-mathieu1
Copy link
Contributor

Description:

I’m encountering an issue when using the DockerComposeCmd struct, as it invokes docker-compose (with a hyphen) to manage containers. This is not compatible with Docker Compose V2, which uses the docker compose command (without the hyphen).

The current implementation in the library executes commands like:

let output = Command::new("docker-compose")
    .arg("-f")
    .arg(self.file.clone())
    .arg("up")
    .arg("-d")
    .output()
    .expect("Failed to execute command");

However, Docker Compose V2 is invoked using docker compose instead of docker-compose, which causes the command to fail when using the V2 plugin version of Docker Compose.

Expected Behavior:

The library should support both the legacy docker-compose command (for Docker Compose V1) and the new docker compose command (for Docker Compose V2). This would allow compatibility with both versions of Docker Compose.

Suggested Solution:

I suggest modifying the command invocation logic in the DockerComposeCmd struct to check for the available version of Docker Compose (V1 vs V2) and call the appropriate command:

Check if Docker Compose V2 is installed: We can attempt to invoke docker compose and fall back to docker-compose if the former isn't available.

Example Fix:

fn get_docker_compose_command() -> &'static str {
    if Command::new("docker").arg("compose").output().is_ok() {
        "docker compose"
    } else {
        "docker-compose"
    }
}

pub fn up(&self) {
    let docker_compose_cmd = get_docker_compose_command();

    let output = Command::new(docker_compose_cmd)
        .arg("-f")
        .arg(self.file.clone())
        .arg("up")
        .arg("-d")
        .output()
        .expect("Failed to execute command");
    println!("Output: {}", String::from_utf8_lossy(&output.stdout));
    println!("Errors: {}", String::from_utf8_lossy(&output.stderr));
    println!("Docker Compose started");
    
    // Further logic remains unchanged...
}

Steps to Reproduce:

  • Use Docker Compose V2 (plugin version) with the current version of rusty-docker-compose.
  • Run the up method in DockerComposeCmd.
  • The command fails due to the attempt to invoke docker-compose instead of docker compose.
@damien-mathieu1
Copy link
Contributor Author

I will take it, I just did a PR #5 to handle different compose version. It would be very much appreciated if it is addressed, I would like to use your crate on my project 😄

@lwlee2608 lwlee2608 added the enhancement New feature or request label Feb 3, 2025
@lwlee2608
Copy link
Owner

Thank you for your contribution! It's definitely good to support both Docker Compose v1 and v2.

@lwlee2608
Copy link
Owner

Fixed in #5

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request
Projects
None yet
Development

No branches or pull requests

2 participants