Comments (6)
Did you try to share the file from the host to the container?
For example:
version: '3'
services:
service:
image: image
ports:
- 8080:8080
restart: always
network_mode: "host"
volumes:
- /etc/machine-id:/etc/machine-id
- /var/lib/dbus/machine-id:/var/lib/dbus/machine-id
from machineid.
If neither of these paths exists, an empty string will be returned.
Instead of getting a wrong id, it's better to generate one.
// +build linux
package machineid
const (
// dbusPath is the default path for dbus machine id.
dbusPath = "/var/lib/dbus/machine-id"
// dbusPathEtc is the default path for dbus machine id located in /etc.
// Some systems (like Fedora 20) only know this path.
// Sometimes it's the other way round.
dbusPathEtc = "/etc/machine-id"
uuid = "/proc/sys/kernel/random/uuid"
)
// machineID returns the uuid specified at `/var/lib/dbus/machine-id` or `/etc/machine-id`.
// If there is an error reading the files an empty string is returned.
// See https://unix.stackexchange.com/questions/144812/generate-consistent-machine-unique-id
func machineID() (string, error) {
id, err := readFile(dbusPath)
if err != nil {
// try fallback path
id, err = readFile(dbusPathEtc)
}
if err != nil {
id, err = readFile(uuid)
if err == nil {
writeFile(dbusPathEtc, id)
}
}
if err != nil {
return "", err
}
return trim(string(id)), nil
}
func writeFile(filename string, data []byte) error {
return ioutil.WriteFile(filename, data, 644)
}
It works fine for my docker image
from machineid.
If neither of these paths exists, an empty string will be returned.
Instead of getting a wrong id, it's better to generate one.
Since this repository seems unmaintained, I implemented a variation of this logic in github.com/panta/machineid, where it's also possible to specify the machine-id file using the MACHINE_ID_FILE
env var.
Obviously I'd be more that happy if the changes were merged upstream!
from machineid.
Joining the party. It would be great to support docker by getting unique ids per container.
from machineid.
This is a great library, thanks so much for writing it.
It would be great if docker containerisation were detected, and then a unique container ID or some information was used as the machine ID - or if it exposed a Docker ID and the machine ID, and both could be used as a third unique ID.
from machineid.
Is there any progress on this?
from machineid.
Related Issues (11)
- FreeNAS (FreeBSD variant) doesn't display any content with smbios.system.uuid property HOT 2
- Machineid can be edited not unique in docker container HOT 2
- OS centos6 error
- Supporting an alternate source for machine-id for testing purposes? HOT 1
- [question] using machineid on docker container. HOT 1
- ESXi host support HOT 1
- Error while getting machine id in Windows 10 HOT 9
- Docker machine-id fails
- Why different machines has same machineId? HOT 2
- OpenBSD uses machine-id HOT 3
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from machineid.