Skip to content

Commit de40167

Browse files
Merge pull request #563 from jesseduffield/docker-compose-command-update
Use 'docker compose' by default
2 parents 4f375bb + df6c8c1 commit de40167

File tree

5 files changed

+21
-20
lines changed

5 files changed

+21
-20
lines changed

README.md

Lines changed: 0 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -296,12 +296,6 @@ By default we only show logs from the last hour, so that we're not putting too m
296296
297297
If you are running lazydocker in Docker container, it is a know bug, that you can't see logs or CPU usage.
298298

299-
### Why isn't my docker-compose environment being used?
300-
301-
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.
302-
303-
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.
304-
305299
## Alternatives
306300

307301
- [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.

docs/Config.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -65,7 +65,7 @@ logs:
6565
since: '60m' # set to '' to show all logs
6666
tail: '' # set to 200 to show last 200 lines of logs
6767
commandTemplates:
68-
dockerCompose: docker-compose # Determines the Docker Compose command to run, referred to as .DockerCompose in commandTemplates
68+
dockerCompose: docker compose # Determines the Docker Compose command to run, referred to as .DockerCompose in commandTemplates
6969
restartService: '{{ .DockerCompose }} restart {{ .Service.Name }}'
7070
up: '{{ .DockerCompose }} up -d'
7171
down: '{{ .DockerCompose }} down'

pkg/commands/docker.go

Lines changed: 13 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -113,12 +113,7 @@ func NewDockerCommand(log *logrus.Entry, osCommand *OSCommand, tr *i18n.Translat
113113
Closers: []io.Closer{tunnelCloser},
114114
}
115115

116-
command := utils.ApplyTemplate(
117-
config.UserConfig.CommandTemplates.CheckDockerComposeConfig,
118-
dockerCommand.NewCommandObject(CommandObject{}),
119-
)
120-
121-
log.Warn(command)
116+
dockerCommand.setDockerComposeCommand(config)
122117

123118
err = osCommand.RunCommand(
124119
utils.ApplyTemplate(
@@ -134,6 +129,18 @@ func NewDockerCommand(log *logrus.Entry, osCommand *OSCommand, tr *i18n.Translat
134129
return dockerCommand, nil
135130
}
136131

132+
func (c *DockerCommand) setDockerComposeCommand(config *config.AppConfig) {
133+
if config.UserConfig.CommandTemplates.DockerCompose != "docker compose" {
134+
return
135+
}
136+
137+
// 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'
138+
err := c.OSCommand.RunCommand("docker compose version")
139+
if err != nil {
140+
config.UserConfig.CommandTemplates.DockerCompose = "docker-compose"
141+
}
142+
}
143+
137144
func (c *DockerCommand) Close() error {
138145
return utils.CloseMany(c.Closers)
139146
}

pkg/config/app_config.go

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -168,7 +168,7 @@ type CommandTemplatesConfig struct {
168168

169169
// DockerCompose is for your docker-compose command. You may want to combine a
170170
// few different docker-compose.yml files together, in which case you can set
171-
// this to "docker-compose -f foo/docker-compose.yml -f
171+
// this to "docker compose -f foo/docker-compose.yml -f
172172
// bah/docker-compose.yml". The reason that the other docker-compose command
173173
// templates all start with {{ .DockerCompose }} is so that they can make use
174174
// of whatever you've set in this value rather than you having to copy and
@@ -200,7 +200,7 @@ type CommandTemplatesConfig struct {
200200
// and ensure they're running before trying to run the service at hand
201201
RecreateService string `yaml:"recreateService,omitempty"`
202202

203-
// AllLogs is for showing what you get from doing `docker-compose logs`. It
203+
// AllLogs is for showing what you get from doing `docker compose logs`. It
204204
// combines all the logs together
205205
AllLogs string `yaml:"allLogs,omitempty"`
206206

@@ -385,7 +385,7 @@ func GetDefaultConfig() UserConfig {
385385
Tail: "",
386386
},
387387
CommandTemplates: CommandTemplatesConfig{
388-
DockerCompose: "docker-compose",
388+
DockerCompose: "docker compose",
389389
RestartService: "{{ .DockerCompose }} restart {{ .Service.Name }}",
390390
StartService: "{{ .DockerCompose }} start {{ .Service.Name }}",
391391
Up: "{{ .DockerCompose }} up -d",
@@ -502,7 +502,7 @@ func NewAppConfig(name, version, commit, date string, buildSource string, debugg
502502
return nil, err
503503
}
504504

505-
// Pass compose files as individual -f flags to docker-compose
505+
// Pass compose files as individual -f flags to docker compose
506506
if len(composeFiles) > 0 {
507507
userConfig.CommandTemplates.DockerCompose += " -f " + strings.Join(composeFiles, " -f ")
508508
}

pkg/config/app_config_test.go

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@ func TestDockerComposeCommandNoFiles(t *testing.T) {
1515
}
1616

1717
actual := conf.UserConfig.CommandTemplates.DockerCompose
18-
expected := "docker-compose"
18+
expected := "docker compose"
1919
if actual != expected {
2020
t.Fatalf("Expected %s but got %s", expected, actual)
2121
}
@@ -29,7 +29,7 @@ func TestDockerComposeCommandSingleFile(t *testing.T) {
2929
}
3030

3131
actual := conf.UserConfig.CommandTemplates.DockerCompose
32-
expected := "docker-compose -f one.yml"
32+
expected := "docker compose -f one.yml"
3333
if actual != expected {
3434
t.Fatalf("Expected %s but got %s", expected, actual)
3535
}
@@ -43,7 +43,7 @@ func TestDockerComposeCommandMultipleFiles(t *testing.T) {
4343
}
4444

4545
actual := conf.UserConfig.CommandTemplates.DockerCompose
46-
expected := "docker-compose -f one.yml -f two.yml -f three.yml"
46+
expected := "docker compose -f one.yml -f two.yml -f three.yml"
4747
if actual != expected {
4848
t.Fatalf("Expected %s but got %s", expected, actual)
4949
}

0 commit comments

Comments
 (0)