From df6c8c196e218bdff48e72824dfd0da43335f05d Mon Sep 17 00:00:00 2001 From: Jesse Duffield Date: Sun, 21 Jul 2024 21:27:51 +1000 Subject: [PATCH] Use 'docker compose' by default We now fall back to 'docker-compose' if need be --- README.md | 6 ------ docs/Config.md | 2 +- pkg/commands/docker.go | 19 +++++++++++++------ pkg/config/app_config.go | 8 ++++---- pkg/config/app_config_test.go | 6 +++--- 5 files changed, 21 insertions(+), 20 deletions(-) diff --git a/README.md b/README.md index 69c019498..29b0a3126 100644 --- a/README.md +++ b/README.md @@ -296,12 +296,6 @@ By default we only show logs from the last hour, so that we're not putting too m If you are running lazydocker in Docker container, it is a know bug, that you can't see logs or CPU usage. -### Why isn't my docker-compose environment being used? - -By default Compose V1 (`docker-compose` with the hyphen) is used as the docker-compose command. You will need to make sure you have the `docker-compose` command available for lazydocker to be able to use. - -If you use Compose V2 (`docker compose` without the hyphen), alternatively, you can change the docker-compose command used via the `commandTemplates.dockerCompose` config value. - ## Alternatives - [docui](https://github.com/skanehira/docui) - Skanehira beat me to the punch on making a docker terminal UI, so definitely check out that repo as well! I think the two repos can live in harmony though: lazydocker is more about managing existing containers/services, and docui is more about creating and configuring them. diff --git a/docs/Config.md b/docs/Config.md index 254adc4fe..e43bdf904 100644 --- a/docs/Config.md +++ b/docs/Config.md @@ -65,7 +65,7 @@ logs: since: '60m' # set to '' to show all logs tail: '' # set to 200 to show last 200 lines of logs commandTemplates: - dockerCompose: docker-compose # Determines the Docker Compose command to run, referred to as .DockerCompose in commandTemplates + dockerCompose: docker compose # Determines the Docker Compose command to run, referred to as .DockerCompose in commandTemplates restartService: '{{ .DockerCompose }} restart {{ .Service.Name }}' up: '{{ .DockerCompose }} up -d' down: '{{ .DockerCompose }} down' diff --git a/pkg/commands/docker.go b/pkg/commands/docker.go index f21842381..28c12c233 100644 --- a/pkg/commands/docker.go +++ b/pkg/commands/docker.go @@ -113,12 +113,7 @@ func NewDockerCommand(log *logrus.Entry, osCommand *OSCommand, tr *i18n.Translat Closers: []io.Closer{tunnelCloser}, } - command := utils.ApplyTemplate( - config.UserConfig.CommandTemplates.CheckDockerComposeConfig, - dockerCommand.NewCommandObject(CommandObject{}), - ) - - log.Warn(command) + dockerCommand.setDockerComposeCommand(config) err = osCommand.RunCommand( utils.ApplyTemplate( @@ -134,6 +129,18 @@ func NewDockerCommand(log *logrus.Entry, osCommand *OSCommand, tr *i18n.Translat return dockerCommand, nil } +func (c *DockerCommand) setDockerComposeCommand(config *config.AppConfig) { + if config.UserConfig.CommandTemplates.DockerCompose != "docker compose" { + return + } + + // it's possible that a user is still using docker-compose, so we'll check if 'docker comopose' is available, and if not, we'll fall back to 'docker-compose' + err := c.OSCommand.RunCommand("docker compose version") + if err != nil { + config.UserConfig.CommandTemplates.DockerCompose = "docker-compose" + } +} + func (c *DockerCommand) Close() error { return utils.CloseMany(c.Closers) } diff --git a/pkg/config/app_config.go b/pkg/config/app_config.go index 38bf5c789..9c0ad4745 100644 --- a/pkg/config/app_config.go +++ b/pkg/config/app_config.go @@ -168,7 +168,7 @@ type CommandTemplatesConfig struct { // DockerCompose is for your docker-compose command. You may want to combine a // few different docker-compose.yml files together, in which case you can set - // this to "docker-compose -f foo/docker-compose.yml -f + // this to "docker compose -f foo/docker-compose.yml -f // bah/docker-compose.yml". The reason that the other docker-compose command // templates all start with {{ .DockerCompose }} is so that they can make use // of whatever you've set in this value rather than you having to copy and @@ -200,7 +200,7 @@ type CommandTemplatesConfig struct { // and ensure they're running before trying to run the service at hand RecreateService string `yaml:"recreateService,omitempty"` - // AllLogs is for showing what you get from doing `docker-compose logs`. It + // AllLogs is for showing what you get from doing `docker compose logs`. It // combines all the logs together AllLogs string `yaml:"allLogs,omitempty"` @@ -385,7 +385,7 @@ func GetDefaultConfig() UserConfig { Tail: "", }, CommandTemplates: CommandTemplatesConfig{ - DockerCompose: "docker-compose", + DockerCompose: "docker compose", RestartService: "{{ .DockerCompose }} restart {{ .Service.Name }}", StartService: "{{ .DockerCompose }} start {{ .Service.Name }}", Up: "{{ .DockerCompose }} up -d", @@ -502,7 +502,7 @@ func NewAppConfig(name, version, commit, date string, buildSource string, debugg return nil, err } - // Pass compose files as individual -f flags to docker-compose + // Pass compose files as individual -f flags to docker compose if len(composeFiles) > 0 { userConfig.CommandTemplates.DockerCompose += " -f " + strings.Join(composeFiles, " -f ") } diff --git a/pkg/config/app_config_test.go b/pkg/config/app_config_test.go index 1aa05db6f..5e7c2922a 100644 --- a/pkg/config/app_config_test.go +++ b/pkg/config/app_config_test.go @@ -15,7 +15,7 @@ func TestDockerComposeCommandNoFiles(t *testing.T) { } actual := conf.UserConfig.CommandTemplates.DockerCompose - expected := "docker-compose" + expected := "docker compose" if actual != expected { t.Fatalf("Expected %s but got %s", expected, actual) } @@ -29,7 +29,7 @@ func TestDockerComposeCommandSingleFile(t *testing.T) { } actual := conf.UserConfig.CommandTemplates.DockerCompose - expected := "docker-compose -f one.yml" + expected := "docker compose -f one.yml" if actual != expected { t.Fatalf("Expected %s but got %s", expected, actual) } @@ -43,7 +43,7 @@ func TestDockerComposeCommandMultipleFiles(t *testing.T) { } actual := conf.UserConfig.CommandTemplates.DockerCompose - expected := "docker-compose -f one.yml -f two.yml -f three.yml" + expected := "docker compose -f one.yml -f two.yml -f three.yml" if actual != expected { t.Fatalf("Expected %s but got %s", expected, actual) }