mirror of
https://github.com/amir20/dozzle.git
synced 2025-12-21 21:33:18 +01:00
feat: implements support for custom container names (#3197)
This commit is contained in:
@@ -65,6 +65,7 @@ export default defineConfig({
|
|||||||
{ text: "Actions", link: "/guide/actions" },
|
{ text: "Actions", link: "/guide/actions" },
|
||||||
{ text: "Agent Mode", link: "/guide/agent" },
|
{ text: "Agent Mode", link: "/guide/agent" },
|
||||||
{ text: "Changing Base", link: "/guide/changing-base" },
|
{ text: "Changing Base", link: "/guide/changing-base" },
|
||||||
|
{ text: "Container Names", link: "/guide/container-names" },
|
||||||
{ text: "Container Groups", link: "/guide/container-groups" },
|
{ text: "Container Groups", link: "/guide/container-groups" },
|
||||||
{ text: "Data Analytics", link: "/guide/analytics" },
|
{ text: "Data Analytics", link: "/guide/analytics" },
|
||||||
{ text: "Display Name", link: "/guide/hostname" },
|
{ text: "Display Name", link: "/guide/hostname" },
|
||||||
|
|||||||
30
docs/guide/container-names.md
Normal file
30
docs/guide/container-names.md
Normal file
@@ -0,0 +1,30 @@
|
|||||||
|
---
|
||||||
|
title: Container Names
|
||||||
|
---
|
||||||
|
|
||||||
|
# Container Names
|
||||||
|
|
||||||
|
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.
|
||||||
|
|
||||||
|
## Custom Names
|
||||||
|
|
||||||
|
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.
|
||||||
|
|
||||||
|
Here is an example using Docker Compose or Docker CLI:
|
||||||
|
|
||||||
|
::: code-group
|
||||||
|
|
||||||
|
```sh
|
||||||
|
docker run --label dev.dozzle.name=hello hello-world
|
||||||
|
```
|
||||||
|
|
||||||
|
```yaml [docker-compose.yml]
|
||||||
|
version: "3"
|
||||||
|
services:
|
||||||
|
dozzle:
|
||||||
|
image: hello-world
|
||||||
|
labels:
|
||||||
|
- dev.dozzle.name=hello
|
||||||
|
```
|
||||||
|
|
||||||
|
:::
|
||||||
@@ -356,7 +356,9 @@ func (d *httpClient) SystemInfo() system.Info {
|
|||||||
|
|
||||||
func newContainer(c types.Container, host string) Container {
|
func newContainer(c types.Container, host string) Container {
|
||||||
name := "no name"
|
name := "no name"
|
||||||
if len(c.Names) > 0 {
|
if c.Labels["dev.dozzle.name"] != "" {
|
||||||
|
name = c.Labels["dev.dozzle.name"]
|
||||||
|
} else if len(c.Names) > 0 {
|
||||||
name = strings.TrimPrefix(c.Names[0], "/")
|
name = strings.TrimPrefix(c.Names[0], "/")
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -380,7 +382,9 @@ func newContainer(c types.Container, host string) Container {
|
|||||||
|
|
||||||
func newContainerFromJSON(c types.ContainerJSON, host string) Container {
|
func newContainerFromJSON(c types.ContainerJSON, host string) Container {
|
||||||
name := "no name"
|
name := "no name"
|
||||||
if len(c.Name) > 0 {
|
if c.Config.Labels["dev.dozzle.name"] != "" {
|
||||||
|
name = c.Config.Labels["dev.dozzle.name"]
|
||||||
|
} else if len(c.Name) > 0 {
|
||||||
name = strings.TrimPrefix(c.Name, "/")
|
name = strings.TrimPrefix(c.Name, "/")
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user