Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Container module incorrectly shows "Systemd" in ubuntu:20.04 Docker container #3821

Closed
christoph-blessing opened this issue Mar 31, 2022 · 5 comments · Fixed by #4832
Closed
Assignees
Labels
🐛 bug Something isn't working as expected. 🌱 good first issue Good first issue to get your feet wet.

Comments

@christoph-blessing
Copy link

Current Behavior

The container module shows "Systemd" instead of "Docker" if inside a container created from the ubuntu:20.04 Docker image.

Expected Behavior

It should show "Docker" if inside a Docker container.

Additional context/Screenshots

The container module checks if the path /run/systemd/container exists to determine if it is a Systemd container. For some reason the above mentioned path exists in the mentioned image.

Possible Solution

A relatively simple fix would be to move the check for "Docker" before the one for "Systemd". Currently the Docker check comes after the Systemd check.

Environment

  • Starship version: 1.5.4
  • zsh version: zsh 5.8 (x86_64-ubuntu-linux-gnu)
  • Operating system: Ubuntu 20.04
  • Terminal emulator:
  • Git Commit Hash: d420a63
  • Branch/Tag: v1.5.4
  • Rust Version: rustc 1.59.0 (9d1b2106e 2022-02-23)
  • Rust channel: release
  • Build Time: 2022-03-24 19:18:47 +00:00

Relevant Shell Configuration

<unknown config>

Starship Configuration

[aws]
disabled = true

[container]
format = "[$symbol]($style) "
@christoph-blessing christoph-blessing added the 🐛 bug Something isn't working as expected. label Mar 31, 2022
@davidkna davidkna added the 🌱 good first issue Good first issue to get your feet wet. label Mar 31, 2022
@younes-io
Copy link

I would like to work on this issue

@younes-io
Copy link

younes-io commented Apr 2, 2022

The .dockerenv file was used by the deprecated LXC driver (LXC support has been removed). So, relying on this file may be an issue in the future.

Apparently, the safest way to determine if a process is running inside Docker or not is cat /proc/1/cgroup. If it's running inside Docker, the result will have /docker; so we could use something like grep -cim1 "/docker" /proc/1/cgroup.

@michel-slm
Copy link
Contributor

This also happens when running under podman, and also for Ubuntu 22.04.

@jeka
Copy link

jeka commented Jul 6, 2022

Actually, according to the description of the module the variable $name should contain the container name, not the container engine.
Yes, it shows currently Systemd inside podman container, but even if it is showing Podman or Docker or whatever else is useless info. People usually know what container engine they are using.
Its better to return info as described - the container name which is in most cases is the hostname as seen within the container

@khuongduybui
Copy link

on WSL(v2) now when SystemD is natively supported and enabled, container always show [🔴 Systemd].

ciffelia added a commit to ciffelia/dotfiles that referenced this issue Oct 24, 2022
andytom pushed a commit that referenced this issue Jan 22, 2023
* Fixes #3821 to provide an improved experience for display of container

Details:
- podman containerenv processing is now happens before systemd
- if systemd/container contains "docker", now shows "Docker"
- maintains fix from #4593 to prevent 'Systemd" display on WSL
- refactors tests for systemd detection

* only compile function for linux

* correct 'default' systemd test use use None, codecov caught this mistake

* refactor my change to systemd/container detection so that it has one stage instead of multiple
Indyandie pushed a commit to Indyandie/starship that referenced this issue Jul 26, 2023
…#4832)

* Fixes starship#3821 to provide an improved experience for display of container

Details:
- podman containerenv processing is now happens before systemd
- if systemd/container contains "docker", now shows "Docker"
- maintains fix from starship#4593 to prevent 'Systemd" display on WSL
- refactors tests for systemd detection

* only compile function for linux

* correct 'default' systemd test use use None, codecov caught this mistake

* refactor my change to systemd/container detection so that it has one stage instead of multiple
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
🐛 bug Something isn't working as expected. 🌱 good first issue Good first issue to get your feet wet.
Projects
None yet
Development

Successfully merging a pull request may close this issue.

6 participants