Docker 32-bit Image downloaded, but tells its a 64-bit architecture
Asked Answered
R

4

6

I might be entirely wrong here but, I pulled 32bit/ubuntu from docker registry and wen I run uname -a I get x86_64

➜  ~  docker images
REPOSITORY               TAG                 IMAGE ID            CREATED             VIRTUAL SIZE
erlang-build-box         latest              fd61e832201b        7 weeks ago         1.841 GB
hello-world              latest              e45a5af57b00        9 weeks ago         910 B
32bit/ubuntu             14.04               6de534a1b6e3        4 months ago        290.7 MB
phusion/passenger-full   0.9.10              29eb0419ab6f        10 months ago       649.3 MB
➜  ~  docker run -t -i 6de534a1b6e3 /bin/bash
root@c40d7c09be96:/# uname -a 
Linux c40d7c09be96 3.16.7-tinycore64 #1 SMP Tue Dec 16 23:03:39 UTC 2014 x86_64 x86_64 x86_64 GNU/Linux
root@c40d7c09be96:/# uname -m
x86_64
root@c40d7c09be96:/# 

Am I wrong in my understanding that this machine is 64bit?

Ruperto answered 9/3, 2015 at 22:11 Comment(0)
C
7

Docker containers always use the kernel from the host. You have a 64bit host, so that's what it's reporting.

The container image is 32-bit in the sense that all the binaries are 32-bit and could be processed by a 32-bit architecture.

Docker does not do virtualisation.

Chantry answered 9/3, 2015 at 22:55 Comment(1)
And to check the architecture of containers binaries, you can check them using command file. Ie.: file /bin/bashMargit
G
2

extract from https://github.com/docker/docker/issues/611

uname will always tell you 64 bits. Look at e.g. "file /bin/sh" to see the real arch of the filesystem.

Glottal answered 10/3, 2015 at 7:41 Comment(0)
H
0

Just a note: systemd-nspawn can "virtualize" the processor mode, and trick the processes inside to believe it is a 32-bit processor (tested by me). AFAIK, LXC can too.

And I mean that running "uname -m" returns "i686" (and my host OS is running in 64 bit mode)

Highstrung answered 28/9, 2015 at 8:37 Comment(0)
B
0

Some specific code examples for cases where you only need to distinguish between running in i686 and x86_64 docker containers and don't need to handle other architectures.

Instead of checking the kernel type as follows:

if [ "$(uname -m)" = "x86-64" ]; then
  ... 64-bit code ...
else
  ... 32-bit code ...
fi

The system binary build type can be checked with:

if [ "$(file -bL /bin/sh | cut -f 2 -d ' ')" = "64-bit" ]; then
  ... 64-bit code ...
else
  ... 32-bit code ...
fi
Brass answered 6/9, 2022 at 4:32 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.