问题描述
当我创建 32 位 CentOS 5 docker 映像时,我希望将 cpu 架构报告为 i386/i686(在此容器检查架构中测试并安装 64 位二进制文件而不是 32 位的安装程序).我设置了 yum 变量并创建了 uname 包装器,因此 yum 和 bash 脚本中的检查工作正常:
When I create 32 bit CentOS 5 docker image I would like cpu architecture to be reported as i386/i686 there (installer which tested in this container check architecture and installs 64 bit binaries instead of 32 bit).I set yum variables and created uname wrapper, so yum and checks in bash scripts are working:
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
但是python还是报64位
But python still reports 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')
有没有办法到处伪造 cpu 架构?
Is there a way to fake cpu architecture everywhere?
推荐答案
我希望有一个更优雅的方法来做到这一点,但这是我所做的:在你想用 linux32
运行的任何命令前加上.例如:
I hope there's a more elegant way to do this, but here's what I do: preface any command you want to run with linux32
. For example:
$ docker run -t -i toopher/centos-i386:centos6 /bin/bash
[root@b027ad7830ac /]# 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
[root@b027ad7830ac /]# linux32 uname -a
Linux b027ad7830ac 3.16.4-tinycore64 #1 SMP Thu Oct 23 16:14:24 UTC 2014 i686 i686 i386 GNU/Linux
[root@b027ad7830ac /]# 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')
您也可以在 docker run
的调用中使用 linux32
:
Alternatively you can use linux32
in the invocation of docker run
:
$ docker run -t -i toopher/centos-i386:centos6 /usr/bin/linux32 /bin/bash
[root@0f289d955fe1 /]# uname -a
Linux 0f289d955fe1 3.16.4-tinycore64 #1 SMP Thu Oct 23 16:14:24 UTC 2014 i686 i686 i386 GNU/Linux
[root@0f289d955fe1 /]# 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')
或者更好的是,使用将 linux32
配置为 ENTRYPOINT
的 docker 映像(或构建自己的),例如:
Or even better, use a docker image (or build your own) that configures linux32
as it's ENTRYPOINT
, such as:
FROM toopher/centos-i386:centos6
ENTRYPOINT ["linux32"]
这篇关于如何在 docker 容器中伪造 cpu 架构?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!