如何在Docker容器中伪造CPU架构? [英] How to fake cpu architecture in docker container?

查看:418
本文介绍了如何在Docker容器中伪造CPU架构?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

当我创建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')

或者,您可以在<$ c的调用中使用 linux32 $ c> docker run

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 的docker镜像(或构建自己的镜像),因为它是 ENTRYPOINT ,例如:

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架构?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆