由于GLIBC及C++运行时库的问题,在新的Ubuntu下编译的软件,拿到老系统上,是往往会运行出错的,而老系统编译出来的软件,则通常能够被新系统兼容
因此准备弄一个老系统下的容器,专门用来编译一些软件,这里ubuntu使用16.04版本。
参考自网络上搜索得到的信息,
准备三个文件,分别是Dockerfile/run.sh/sources.list
其中sources.list是方便国内快速拉取得相应的软件包,内容如下:
deb-src http://archive.ubuntu.com/ubuntu xenial main restricted #Added by software-properties
deb http://mirrors.aliyun.com/ubuntu/ xenial main restricted
deb-src http://mirrors.aliyun.com/ubuntu/ xenial main restricted multiverse universe #Added by software-properties
deb http://mirrors.aliyun.com/ubuntu/ xenial-updates main restricted
deb-src http://mirrors.aliyun.com/ubuntu/ xenial-updates main restricted multiverse universe #Added by software-properties
deb http://mirrors.aliyun.com/ubuntu/ xenial universe
deb http://mirrors.aliyun.com/ubuntu/ xenial-updates universe
deb http://mirrors.aliyun.com/ubuntu/ xenial multiverse
deb http://mirrors.aliyun.com/ubuntu/ xenial-updates multiverse
deb http://mirrors.aliyun.com/ubuntu/ xenial-backports main restricted universe multiverse
deb-src http://mirrors.aliyun.com/ubuntu/ xenial-backports main restricted universe multiverse #Added by software-properties
deb http://archive.canonical.com/ubuntu xenial partner
deb-src http://archive.canonical.com/ubuntu xenial partner
deb http://mirrors.aliyun.com/ubuntu/ xenial-security main restricted
deb-src http://mirrors.aliyun.com/ubuntu/ xenial-security main restricted multiverse universe #Added by software-properties
deb http://mirrors.aliyun.com/ubuntu/ xenial-security universe
deb http://mirrors.aliyun.com/ubuntu/ xenial-security multiverse
而run.sh只用来启动ssh服务器,方便容器运行时远程登陆进去操作,内容如下:
#!/bin/bash
if [[ ! -e /data ]]; then
mkdir /data
fi
/usr/sbin/sshd -D
Dockerfile内容如下:
# 以最新的Ubuntu镜像为模板
FROM ubuntu:16.04
# 将本目录下的sources.list作为容器的一个文件
ADD sources.list /root/sources.list
# 使用阿里Ubuntu源,更新快
RUN mv /etc/apt/sources.list /etc/apt/sources.list_bak
RUN cp /root/sources.list /etc/apt/sources.list
RUN apt-get update
# 安装ssh
RUN apt-get install -y openssh-server
# 安装编译器等相关套件
RUN apt-get install -y build-essential libgmp-dev libmpfr-dev libmpc-dev gawk flex bison pkg-config g++ autoconf automake
# 创建目录
RUN mkdir -p /var/run/sshd
# 创建/data目录
RUN mkdir -p /data
# 修改root密码,便于远程登录
RUN echo root:Test1234 | chpasswd
# 配置ssh可以使用root登陆
RUN sed -i 's/PermitRootLogin prohibit-password/PermitRootLogin yes/' /etc/ssh/sshd_config
# 复制配置文件到相应位置,并赋予脚本可执行权限
ADD run.sh /run.sh
RUN chmod 755 /run.sh
# 开放22端口
EXPOSE 22
#设置自启动命令
CMD ["/run.sh"]
使用命令构造镜像,如下(由于机器的原因,构造镜像及运行容器时,域名解析会出错,这里直接add-host一下):
docker build \
--add-host archive.ubuntu.com:185.125.190.81 \
--add-host mirrors.aliyun.com:101.226.27.113 \
--add-host archive.canonical.com:185.125.188.87 \
-t base_env:16.04 .
运行容器如下(将home目录及data目录映射进容器,同时容器外的12306端口映射进容器的22端口):
docker run -d \
--add-host archive.ubuntu.com:185.125.190.81 \
--add-host mirrors.aliyun.com:101.226.27.113 \
--add-host archive.canonical.com:185.125.188.87 \
-v /home:/home:rw \
-v /data:/data:rw \
-p 12306:22 \
--name=bld_env_16.04 \
base_env:16.04
标签:http,Linux,xenial,编译,aliyun,ubuntu,Docker,com,deb
From: https://www.cnblogs.com/eaglexmw/p/18586421