<p>I have a go routine running in docker container. I need output of the command dmidecode. But its coming blank.</p>
<p>Go:</p>
<p>func main() {</p>
<pre><code>    cmd := exec.Command(&quot;dmidecode&quot;,&quot;-t 1&quot;)
    x,_ := cmd.Output()
    fmt.Println(&quot;output =======&quot;, string(x))
</code></pre>
<p>}</p>
<p>Docker run:</p>
<p>docker run --device /dev/mem:/dev/mem --cap-add SYS_RAWIO -p 8086:8086 -it my_img:1.0.1</p>
<p>What am I missing here?</p>
<p><strong>Updated:</strong></p>
<p>The above worked in docker after I added below in Dockerfile:</p>
<p>FROM alpine:latest
RUN apk --no-cache --update --verbose add grep bash dmidecode &amp;&amp; <br />
rm -rf /var/cache/apk/* /tmp/* /sbin/halt /sbin/poweroff /sbin/reboot</p>
<p>And below in docker compose file:</p>
<p>privileged: true</p>
<p><strong>But When tried to use the above in kubernetes it not able to fetch demidecode output.</strong></p>
<p>A help will be really appreciated.</p>

<blockquote>
<p>What am I missing here?</p>
</blockquote>
<p>For starters ,error handling.</p>
<pre><code>    x,_ := cmd.Output()
</code></pre>
<p>Never, ever ignore an error in Go.  Unlike languages like, say, Pyhton, there is no exception raising - handling error return values is your <em>only</em> chance to figure out if something went wrong.</p>
<p>Secondly, you're also ignoring your command's Standard Output stream. This is likely to contain a useful error message whenever a command execution doesn't work, so <a href="https://pkg.go.dev/os/exec#Cmd.Output" rel="nofollow noreferrer"><code>os/exec</code>'s <code>Output()</code> provides it as part of the error value</a> if not already captured in the <code>Cmd</code> configuration.  Part of your error handling should be doing a <a href="https://go.dev/tour/methods/15" rel="nofollow noreferrer">type assertion</a> on that error value, if not nil, and if it's a valid <code>*exec.ExitError</code>, and if that type assertion succeeds, check <a href="https://pkg.go.dev/os/exec#ExitError" rel="nofollow noreferrer">its Stderr field</a> for an error message.</p>
<p>Third, looking at your command, I can see you made an easy mistake:</p>
<pre><code>    cmd := exec.Command(&quot;dmidecode&quot;,&quot;-t 1&quot;)
</code></pre>
<p>At the <em>shell</em>, whitespace separates arguments.  but there is no shell here; you're passing <code>-t 1</code> all as one argument to <code>dmidecode</code>.  You should be passing them as <em>separate</em> arguments, almost certainly:</p>
<pre><code>    cmd := exec.Command(&quot;dmidecode&quot;,&quot;-t&quot;, &quot;1&quot;)
</code></pre>
<p>Finally, you've already found  <a href="https://stackoverflow.com/questions/54068234/cant-run-dmidecode-on-docker-container/70084824#70084824">Can&#39;t run dmidecode on docker container</a> , but make sure to read and understand the accepted answer.  Then, get your docker container configured to be able to run <code>dmidecode</code> without Go.  Once it works at the command line, the same docker configuration should allow it to work under Go invocation as well.</p>
