暂无图片
暂无图片
暂无图片
暂无图片
暂无图片

构建基于centos7.6 的postgresql 11.6 镜像

运维笔记本 2020-01-16
999

构建基于centos7.6 的postgresql 11.6 镜像

1.编写Dockerfile

Dockerfile

    FROM centos:centos7.6.1810


    ENV PGHOME usr/local/pgsql-11.6 \
    PGDATA pgdata/data


    RUN yum install -y perl-ExtUtils-Embed readline-devel zlib-devel pam-devel libxml2-devel libxslt-devel openldap-devel python-devel gcc-c++ openssl-devel cmake make gettext gettext-devel


    RUN useradd postgres \
    && mkdir -p pgdata/data \
    && chown postgres.postgres -R pgdata/


    ADD postgresql-11.6.tar.gz postgresql


    RUN postgresql/postgresql-11.6/configure --prefix=/usr/local/pgsql-11.6 --with-segsize=16 --with-wal-segsize=512 --with-blocksize=32 --with-wal-blocksize=64 --with-libxslt --enable-thread-safety --with-pgport=5432 --with-libedit-preferred --with-perl --with-openssl --with-libxml --with-libxslt --enable-thread-safety --enable-nls=en_US.UTF-8 \
    && make \
    && make install


    USER postgres
    ENV PGHOME=/usr/local/pgsql-11.6
    ENV PGDATA=/pgdata/data
    ENV LD_LIBRARY_PATH=$LD_LIBRARY_PATH:$PGHOME/lib
    ENV PATH=$PATH:$PGHOME/bin/


    RUN /usr/local/pgsql-11.6/bin/initdb -D /pgdata/data \
    && /usr/local/pgsql-11.6/bin/pg_ctl -D /pgdata/data -l /pgdata/data/logfile start




    # Adjust PostgreSQL configuration so that remote connections to the
    # database are possible.
    RUN echo "host all all 0.0.0.0/0 md5" >> /pgdata/data/pg_hba.conf


    # And add ``listen_addresses`` to ``/etc/postgresql/9.3/main/postgresql.conf``
    RUN echo "listen_addresses='*'" >> /pgdata/data/postgresql.conf


    # Expose the PostgreSQL port
    EXPOSE 5432
    WORKDIR /home/postgres
    CMD ["/usr/local/pgsql-11.6/bin/postgres","-D","/pgdata/data"]


    # 用下面的命令在docker里面启动pg的时候会使docker自动退出。不知原因
    #CMD ["/usr/local/pgsql-11.6/bin/pg_ctl","-D","/pgdata/data","-l","/pgdata/data/logfile","start"]

    这里有个问题,在Dockerfile中无法使用ENV中的环境变量??

    2.构建

      docker build -t postgresql:11.6-centos7.6 .

      3.运行

        docker run -it -d --name pg1 postgresql_centos

        4.进入容器

          docker exec -it pg1 /bin/bash

          5.推送到docker hub

            # 修改tag
            docker tag 20190d1e3d8d haoxy/postgresql:11.6-centos7.6
            docker images
            REPOSITORY TAG IMAGE ID CREATED SIZE
            haoxy/postgresql 11.6-centos7.6 20190d1e3d8d 8 minutes ago 788MB


            # 推送到docker hub
            docker push haoxy/postgresql:11.6-centos7.6

            参考:

            PostgreSQL源码安装及配置

            http://www.freeoa.net/osuport/db/postgresql-source-compile-install-config_3141.html

            最后修改时间:2020-01-17 09:34:56
            文章转载自运维笔记本,如果涉嫌侵权,请发送邮件至:contact@modb.pro进行举报,并提供相关证据,一经查实,墨天轮将立刻删除相关内容。

            评论