从rhel6.5镜像构builddocker镜像

我试图build立一个基于python3的容器,并安装一些要求。 但python3的构build失败在这里我的Dockerfile

FROM rhel6.5 ADD ./* /app/ WORKDIR /app/Python CMD ["./configure"] CMD ["make"] CMD ["altinstall"] WORKDIR /app CMD ["python", "-m", "pip", "install" , "-r" , "requirement.txt"] 

编译后,当我运行

sudo docker run myimage python -v给出了2.6的时候,我运行了bash并试图再次编译python

 sudo docker run -i myimage /bin/bash ./configure 

我有

 ./configure checking build system type... x86_64-unknown-linux-gnu checking host system type... x86_64-unknown-linux-gnu checking for --enable-universalsdk... no checking for --with-universal-archs... no checking MACHDEP... linux checking for --without-gcc... no checking for gcc... no checking for cc... no checking for cl.exe... no configure: error: in `/app': configure: error: no acceptable C compiler found in $PATH See `config.log' for more details 

最后

 yum install gcc 

也失败了

 Loaded plugins: product-id, subscription-manager Setting up Install Process No package gcc available. Error: Nothing to do 

确实有更多的步骤来构buildPython,这里是我最近用于Python 2.7.9的步骤(我相信很容易适应3.4):

  • sudo yum groupinstall“开发工具”
  • sudo yum安装zlib-devel bzip2-devel openssl-devel ncurses-devel sqlite-devel readline-devel tk-devel gdbm-devel db4-devel libpcap-devel xz-devel
  • curl https://www.python.org/ftp/python/2.7.9/Python-2.7.9.tgz -o〜/ Python-2.7.9.tgz
  • tar -xvf Python-2.7.9.tgz
  • CD Python-2.7.9
  • ./configure –prefix = / usr / local –enable-unicode = ucs4 –enable-shared LDFLAGS =“ – Wl,-rpath / usr / local / lib”
  • sudo vi /etc/ld.so.conf
  • 在新行添加/ usr / local / lib并保存。
  • sudo / sbin / ldconfig
  • 使
  • sudo使altinstall
  • 删除Python-2.7.9文件夹和Python-2.7.9.tgz存档

因为你正在编写一个Dockerfile你应该:

  • 使用yum install -y来安装依赖关系
  • 由于您正在altinstalling python解释器,可以在/usr/local/bin/python2.7或python3.4中使用,具体取决于您要安装的版本。
  • make altinstall而不是make install的全部目的是为了确保不会中断python可执行文件的系统依赖关系。

您正在使用RHEL映像; 红帽企业Linux是一种商业产品,需要付费订阅才能访问更新。 除非使用subscription-manager attachconfiguration一些subscription-manager attach否则不会configuration任何存储库。

如果您目前不是付费的RHEL客户,并且您没有强制要求RHEL的理由,则可以通过使用CentOS来有效地访问相同的一组软件包。

另外请注意,目前的fedoraubuntu镜像都提供了Python 3(作为Fedora的可安装软件包,默认包含在Ubuntu中)。

你的Dockerfile是错误的。 您正在使用CMD而不是RUN 。 请参阅有关Dockerfile的参考文档: https ://docs.docker.com/reference/builder/。

CMD的主要目的是为正在执行的容器提供默认值。

然后build立CMD没有任何东西; 它只是元数据,只有最后一个是从图像运行容器时执行。

如果你使用下面的代码,docker将无法构build(但是有一个很好的理由)。

 FROM rhel6.5 ADD ./* /app/ WORKDIR /app/Python RUN ./configure RUN make RUR altinstall WORKDIR /app RUN python -m pip install -r requirement.txt 

您可能想要添加一个步骤来安装编译器和所需的依赖关系,以便能够在您的rhel中构buildpython。 但是我会遵循@larsks和@Adrian Mouat的build议。

深受Teodore的回应和https://registry.hub.docker.com/u/danzilla/centos6-python3-django/dockerfile/

并添加

 ADD ./* /app/ RUN pip3.4 install -r /app/requirement.txt 

在和文件。 哪里需求是我的项目所需要的。

 sudo docker run python3-redhat /usr/local/bin/python3.4 -c "import dja ngo; print(django.get_version())" 

按预期给出1.8.1。