Skip to content

Commit

Permalink
Merge pull request #563 from jesseduffield/docker-compose-command-update
Browse files Browse the repository at this point in the history
Use 'docker compose' by default
  • Loading branch information
jesseduffield authored Jul 21, 2024
2 parents 4f375bb + df6c8c1 commit de40167
Show file tree
Hide file tree
Showing 5 changed files with 21 additions and 20 deletions.
6 changes: 0 additions & 6 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down
2 changes: 1 addition & 1 deletion docs/Config.md
Original file line number Diff line number Diff line change
Expand Up @@ -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'
Expand Down
19 changes: 13 additions & 6 deletions pkg/commands/docker.go
Original file line number Diff line number Diff line change
Expand Up @@ -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(
Expand All @@ -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)
}
Expand Down
8 changes: 4 additions & 4 deletions pkg/config/app_config.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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"`

Expand Down Expand Up @@ -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",
Expand Down Expand Up @@ -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 ")
}
Expand Down
6 changes: 3 additions & 3 deletions pkg/config/app_config_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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)
}
Expand All @@ -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)
}
Expand All @@ -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)
}
Expand Down

0 comments on commit de40167

Please sign in to comment.