Skip to content

Commit acbb2a8

Browse files
authoredAug 13, 2024··
feat: implements support for custom container names (#3197)
1 parent 6c5dcb7 commit acbb2a8

File tree

3 files changed

+37
-2
lines changed

3 files changed

+37
-2
lines changed
 

‎docs/.vitepress/config.ts

+1
Original file line numberDiff line numberDiff line change
@@ -65,6 +65,7 @@ export default defineConfig({
6565
{ text: "Actions", link: "/guide/actions" },
6666
{ text: "Agent Mode", link: "/guide/agent" },
6767
{ text: "Changing Base", link: "/guide/changing-base" },
68+
{ text: "Container Names", link: "/guide/container-names" },
6869
{ text: "Container Groups", link: "/guide/container-groups" },
6970
{ text: "Data Analytics", link: "/guide/analytics" },
7071
{ text: "Display Name", link: "/guide/hostname" },

‎docs/guide/container-names.md

+30
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
1+
---
2+
title: Container Names
3+
---
4+
5+
# Container Names
6+
7+
By default, Dozzle retrieves container names directly from Docker. This is usually sufficient, as these names can be customized using the `--name` flag in `docker run` commands or through the `container_name` field in Docker Compose services.
8+
9+
## Custom Names
10+
11+
In cases where modifying the container name itself isn't possible, you can override it by adding a `dev.dozzle.name` label to your container.
12+
13+
Here is an example using Docker Compose or Docker CLI:
14+
15+
::: code-group
16+
17+
```sh
18+
docker run --label dev.dozzle.name=hello hello-world
19+
```
20+
21+
```yaml [docker-compose.yml]
22+
version: "3"
23+
services:
24+
dozzle:
25+
image: hello-world
26+
labels:
27+
- dev.dozzle.name=hello
28+
```
29+
30+
:::

‎internal/docker/client.go

+6-2
Original file line numberDiff line numberDiff line change
@@ -356,7 +356,9 @@ func (d *httpClient) SystemInfo() system.Info {
356356

357357
func newContainer(c types.Container, host string) Container {
358358
name := "no name"
359-
if len(c.Names) > 0 {
359+
if c.Labels["dev.dozzle.name"] != "" {
360+
name = c.Labels["dev.dozzle.name"]
361+
} else if len(c.Names) > 0 {
360362
name = strings.TrimPrefix(c.Names[0], "/")
361363
}
362364

@@ -380,7 +382,9 @@ func newContainer(c types.Container, host string) Container {
380382

381383
func newContainerFromJSON(c types.ContainerJSON, host string) Container {
382384
name := "no name"
383-
if len(c.Name) > 0 {
385+
if c.Config.Labels["dev.dozzle.name"] != "" {
386+
name = c.Config.Labels["dev.dozzle.name"]
387+
} else if len(c.Name) > 0 {
384388
name = strings.TrimPrefix(c.Name, "/")
385389
}
386390

0 commit comments

Comments
 (0)
Please sign in to comment.