制作一个基本Docker镜像

目录
警告
本文最后更新于 2022-11-22,文中内容可能已过时。

使用 Dockerfile,从源代码开始搭建一个基本的 Docker Image,为其他应用提供基础服务。

Dockerfile

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
FROM centos:centos7.9.2009
MAINTAINER William
LABEL Remarks="CentOS7.9 Develop&Testing Environment @WuyaCapital"

RUN yum update -y && yum install -y \
    sudo vim git make cmake htop\
    gcc gcc-c++ kernel-devel \
    bzip2 mlocate sqlite-devel \
    openssl-devel libcurl-devel chrony \
    wget dmidecode net-tools openssh-server perl-CPAN perl-IPC-Cmd

RUN yum install -y kde-l10n-Chinese && \
    yum reinstall -y glibc-common && \
    localedef -c -f GB18030 -i zh_CN zh_CN.GB18030 && \
    updatedb

RUN cd /tmp && wget --no-check-certificate http://mirrors.ustc.edu.cn/gnu/libc/glibc-2.18.tar.gz && \
    tar -xvf glibc-2.18.tar.gz && \
    cd glibc-2.18 && \
    mkdir build && cd build && \
    ../configure --prefix=/usr --disable-profile --enable-add-ons --with-headers=/usr/include --with-binutils=/usr/bin && \
    make && make install && \
    rm -rf /tmp/glibc*

RUN cd /tmp && mkdir gcc9 && cd gcc9 && \
    wget --no-check-certificate https://ftp.gnu.org/gnu/gcc/gcc-9.2.0/gcc-9.2.0.tar.gz && \
    tar zxvf gcc-9.2.0.tar.gz && \
    cd gcc-9.2.0 && \
    wget --no-check-certificate ftp://gcc.gnu.org/pub/gcc/infrastructure/gmp-6.1.0.tar.bz2 && \
    wget --no-check-certificate ftp://gcc.gnu.org/pub/gcc/infrastructure/mpfr-3.1.4.tar.bz2 && \
    wget --no-check-certificate ftp://gcc.gnu.org/pub/gcc/infrastructure/mpc-1.0.3.tar.gz && \
    wget --no-check-certificate ftp://gcc.gnu.org/pub/gcc/infrastructure/isl-0.18.tar.bz2 && \
    tar jxvf gmp-6.1.0.tar.bz2 && \
    tar zxvf mpc-1.0.3.tar.gz && \
    tar jxvf mpfr-3.1.4.tar.bz2 && \
    tar jxvf isl-0.18.tar.bz2 && \
    ln -s gmp-6.1.0 gmp  && \
    ln -s mpfr-3.1.4 mpfr  && \
    ln -s mpc-1.0.3 mpc && \
    ln -s isl-0.18 isl && \
    sudo ./configure --prefix=/usr/local/gcc9 --enable-bootstrap --enable-checking=release --enable-languages=c,c++ --disable-multilib && \
    make && make install && \
    echo  "export PATH=/usr/local/gcc9/bin:$PATH" >> /etc/profile.d/gcc.sh && \
    source /etc/profile.d/gcc.sh && \
    ln -sv /usr/local/gcc9/include/ /usr/include/gcc && \
    echo "/usr/local/gcc9/lib64" >> /etc/ld.so.conf.d/gcc.conf && \
    ldconfig -v && \
    ldconfig -p |grep gcc && \
    ln -sf /usr/local/gcc9/bin/g++ /usr/bin/g++ && \
    ln -sf /usr/local/gcc9/bin/gcc /usr/bin/gcc && \
    ln -sf /usr/local/gcc9/bin/c++ /usr/bin/c++ && \
    ln -sf /usr/local/gcc9/bin/cc /usr/bin/cc && \
    rm -rf /tmp/gcc*

RUN cd /tmp && wget --no-check-certificate https://www.openssl.org/source/openssl-3.0.7.tar.gz && \
    tar -xvf openssl-3.0.7.tar.gz && \
    cd openssl-3.0.7 && \
    ./config --prefix=/usr/local/openssl --openssldir=/usr/local/openssl no-shared zlib-dynamic && \
    make && make install && \
    ln -s /usr/local/openssl/include/openssl /usr/include/openssl && \
    ln -s /usr/local/openssl/lib/libssl.so.1.1 /usr/local/lib64/libssl.so && \
    ln -s /usr/local/openssl/lib/libssl.so.1.1 /usr/lib64/libssl.so.1.1 && \
    ln -s /usr/local/openssl/lib/libcrypto.so.1.1 /usr/lib64/libcrypto.so.1.1 && \
    ln -s /usr/local/openssl/bin/openssl /usr/bin/openssl && \
    echo "/usr/local/openssl/lib64" >> /etc/ld.so.conf && \
    ldconfig -v && \
    rm -rf /tmp/openssl*

RUN cd /tmp && wget --no-check-certificate https://www.python.org/ftp/python/3.11.0/Python-3.11.0.tar.xz && \
    tar -xvf Python-3.11.0.tar.xz && \
    cd Python-3.11.0 && \
    CFLAGS="-I/usr/local/openssl/include" LDFLAGS="-L/usr/local/openssl/lib64" \
        ./configure --enable-optimizations \
        --enable-loadable-sqlite-extensions \
        --prefix=/usr/local/python3 \
        --with-openssl=/usr/local/openssl && \
    make && make install && \
    ln -s /usr/local/python3/bin/python3 /usr/bin/python3 && \
    ln -s /usr/local/python3/bin/pip3 /usr/bin/pip3 && \
    python3 -m ssl && \
    rm -rf /tmp/Python*

ENV TZ Asia/Shanghai
RUN ln -snf /usr/share/zoneinfo/$TZ /etc/localtime && echo $TZ > /etc/timezone

RUN mkdir -p /shared/trading /data

ENV PATH=/sbin:/bin:/usr/sbin:/usr/bin:/usr/local/sbin:/usr/local/bin
ENV LANG=en_US.UTF-8
ENV BASH_ENV=~/.bashrc \
    ENV=~/.bashrc \
    PROMPT_COMMAND="source ~/.bashrc"
EXPOSE 22 80
WORKDIR /app
CMD ["/usr/sbin/init"]

相关内容

william 支付宝支付宝
william 微信微信
0%