2014-10-21 7 views
8

Wenn ich 32-Bit-CentOS-5-Docker-Bild erstellen möchte ich CPU-Architektur als i386/i686 dort gemeldet werden (Installer, der in diesem Container geprüft Architektur getestet und installiert 64-Bit-Binärdateien anstelle von 32 Bit). Ich habe yum Variablen und erstellt uname Wrapper, so yum und Kontrollen in Bash-Skripte arbeiten:Wie gefälschte CPU Architektur in Docker Container?

bash-3.2# uname -a 
Linux c538cf9bf508 3.13.0-24-generiC#47-Ubuntu SMP Fri May 2 23:30:00 UTC 2014 i686 i686 i386 GNU/Linux 
bash-3.2# uname -p -m -i 
i686 i686 i386 
bash-3.2# cat /etc/yum/vars/arch && cat /etc/yum/vars/basearch 
i686 
i386 

Aber Python berichtet noch 64-Bit-

bash-3.2# python 
Python 2.4.3 (#1, Jan 9 2013, 06:49:54) 
[GCC 4.1.2 20080704 (Red Hat 4.1.2-54)] on linux2 
Type "help", "copyright", "credits" or "license" for more information. 
>>> import os, platform 
>>> platform.machine() 
'x86_64' 
>>> os.uname() 
('Linux', 'c538cf9bf508', '3.13.0-24-generic', '#47-Ubuntu SMP Fri May 2 23:30:00 UTC 2014', 'x86_64') 

Gibt es eine Möglichkeit zu fälschen CPU-Architektur überall?

Antwort

4

Ich hoffe, es gibt eine elegantere Möglichkeit, dies zu tun, aber hier ist, was ich tue: Vorstellen Sie alle Befehle, die Sie mit linux32 ausführen möchten. Zum Beispiel:

$ docker run -t -i toopher/centos-i386:centos6 /bin/bash 
[[email protected] /]# uname -a 
Linux b027ad7830ac 3.16.4-tinycore64 #1 SMP Thu Oct 23 16:14:24 UTC 2014 x86_64 x86_64 x86_64 GNU/Linux 
[[email protected] /]# linux32 uname -a 
Linux b027ad7830ac 3.16.4-tinycore64 #1 SMP Thu Oct 23 16:14:24 UTC 2014 i686 i686 i386 GNU/Linux 
[[email protected] /]# linux32 python 
Python 2.6.6 (r266:84292, Jan 22 2014, 09:37:14) 
[GCC 4.4.7 20120313 (Red Hat 4.4.7-4)] on linux2 
Type "help", "copyright", "credits" or "license" for more information. 
>>> import os, platform 
>>> platform.machine() 
'i686' 
>>> os.uname() 
('Linux', 'b027ad7830ac', '3.16.4-tinycore64', '#1 SMP Thu Oct 23 16:14:24 UTC 2014', 'i686') 

Alternativ können Sie linux32 in dem Aufruf von docker run verwenden:

$ docker run -t -i toopher/centos-i386:centos6 /usr/bin/linux32 /bin/bash 
[[email protected] /]# uname -a 
Linux 0f289d955fe1 3.16.4-tinycore64 #1 SMP Thu Oct 23 16:14:24 UTC 2014 i686 i686 i386 GNU/Linux 
[[email protected] /]# python 
Python 2.6.6 (r266:84292, Jan 22 2014, 09:37:14) 
[GCC 4.4.7 20120313 (Red Hat 4.4.7-4)] on linux2 
Type "help", "copyright", "credits" or "license" for more information. 
>>> import os, platform 
>>> platform.machine() 
'i686' 
>>> os.uname() 
('Linux', '0f289d955fe1', '3.16.4-tinycore64', '#1 SMP Thu Oct 23 16:14:24 UTC 2014', 'i686') 

Oder noch besser, ein Docker Bild (oder bauen Sie Ihre eigenen), die linux32 konfiguriert, wie es ENTRYPOINT ist, wie wie:

+2

Ich versuche es vor zu verwenden, aber nur Paket 64bit gefunden Jetzt habe ich es im Paket Setarch gefunden und es funktioniert gut, danke. Ich stelle es als Einstiegspunkt ein und es sollte mein Problem lösen. – ISanych

+1

Toller Punkt - Ich habe die Antwort aktualisiert, um den 'ENTRYPOINT'-Vorschlag einzuschließen. –

+0

Nur eine Anmerkung: Ich habe toopher/centos-i386: centos6 angefordert, also funktioniert es jetzt gut aus der Box: https://github.com/toopher/toophon-docker/pull/1 –

2

Evans Antwort funktioniert, aber Sie müssen immer noch fast allevoranstellenLinie in Ihrem Dockerfile mit linux32. Um dies zu vermeiden Ich habe folgende in der Nähe der Spitze meines Dockerfile:

RUN rm /bin/sh && \ 
    echo -e '#!/bin/bash\n/usr/bin/linux32 -- /bin/bash "[email protected]"' > /bin/sh && \ 
    chmod +x /bin/sh 

/bin/sh ist normalerweise ein symbolischer Link auf /bin/bash. Dies ersetzt die symbolische Verknüpfung mit dem folgenden Skript:

#!/bin/bash 
/usr/bin/linux32 -- /bin/bash "[email protected]" 

, die jeden Aufruf von RUN in Ihrem Dockerfile Lauf unter linux32 macht. Es sei denn, Sie verwenden das Format RUN ["command"...], das den Aufruf von /bin/sh umgeht. In diesem Fall müssen Sie das Präfix linux32 manuell hinzufügen.

0

Für CentOS, müssen Sie nur die folgenden Dateien ändern:

+RUN echo "i686" > /etc/yum/vars/arch && \ 
+ echo "i386" > /etc/yum/vars/basearch 

(so wie ich in the pull-request to toopher/centos-i386:centos6 tat)

$ docker run -it --rm toopher/centos-i386:centos6 sh 
sh-4.1# python 
Python 2.6.6 (r266:84292, Jan 22 2014, 09:37:14) 
[GCC 4.4.7 20120313 (Red Hat 4.4.7-4)] on linux2 
Type "help", "copyright", "credits" or "license" for more information. 
>>> import os 
>>> os.uname() 
('Linux', 'dc8d1dc46702', '3.16.0-4-amd64', '#1 SMP Debian 3.16.7-ckt11-1+deb8u6 (2015-11-09)', 'i686')