×
Community Blog The Simple Deployment of PolarDB on Docker

The Simple Deployment of PolarDB on Docker

This article introduces how to perform one-click deployment of PolarDB.

By digoal

One-click Deployment of PolarDB

For more information about installing Docker, see: A Guide for Quick MacOS PolarDB-X Deployment

For more information about deploying PolarDB quickly, see: https://apsaradb.github.io/PolarDB-for-PostgreSQL/

Choose any deployment type (single-node instance, multi-node instance, or HTAP instance) as per your requirement. For example:

HTAP instance

# Pull the HTAP PolarDB image.
docker pull polardb/polardb_pg_local_instance:htap    
    
# Create a run and enter the container.
docker run -it --cap-add=SYS_PTRACE --privileged=true --name polardb_pg_htap polardb/polardb_pg_local_instance:htap bash    
    
# Test the instance availability
psql -h 127.0.0.1 -c 'select version();'    
            version    
--------------------------------    
 PostgreSQL 11.9 (POLARDB 11.9)    
(1 row)    

After you exit a container, how can you enter the container again?

IT-C02YW2EFLVDL:~ digoal$ docker ps -a    
CONTAINER ID   IMAGE                                    COMMAND                  CREATED         STATUS                     PORTS     NAMES    
dd43b032b95e   polardb/polardb_pg_local_instance:htap   "/bin/sh -c '~/tmp_b…"   7 minutes ago   Exited (1) 3 minutes ago             polardb_pg_htap    
IT-C02YW2EFLVDL:~ digoal$ docker start dd43b032b95e    
dd43b032b95e    
IT-C02YW2EFLVDL:~ digoal$ docker exec -it dd43b032b95e bash    
    
[postgres@dd43b032b95e ~]$ psql -h 127.0.0.1    
psql (11.9)    
Type "help" for help.    
    
postgres=# \q    

For other information, please refer to docker --help

List containers

IT-C02YW2EFLVDL:~ digoal$ docker ps -a    
CONTAINER ID   IMAGE                                    COMMAND                  CREATED         STATUS         PORTS     NAMES    
dd43b032b95e   polardb/polardb_pg_local_instance:htap   "/bin/sh -c '~/tmp_b…"   8 minutes ago   Up 2 seconds             polardb_pg_htap    

Stop containers

docker stop ...    
  stop        Stop one or more running containers    

Delete containers

docker rm ...    
  rm          Remove one or more containers    
    
docker rm dd43b032b95e    

List Images

docker images     
  images      List images    
    
    
IT-C02YW2EFLVDL:~ digoal$ docker images    
REPOSITORY                          TAG       IMAGE ID       CREATED        SIZE    
polardb/polardb_pg_local_instance   htap      a05bfc3b1310   3 weeks ago    11.5GB    
polardbx/galaxyengine               latest    6c7171b141d6   2 months ago   2.11GB    
polardbx/galaxysql                  latest    1a9a92c774dc   2 months ago   1.14GB    
polardbx/galaxycdc                  latest    a7b7d468cd34   2 months ago   905MB    
polardbx/xstore-tools               latest    d89e74573646   3 months ago   2.69MB    
polardbx/polardbx-init              latest    b3637901782a   3 months ago   6.59MB    

Delete images

docker rmi ...     
  rmi         Remove one or more images    
    
    
IT-C02YW2EFLVDL:~ digoal$ docker rmi 6c7171b141d6    
Untagged: polardbx/galaxyengine:latest    
Untagged: polardbx/galaxyengine@sha256:135530a3848fec0663555decf6d40de4b9b6288e59f0ce9f8fafc88103ee4b53    
Deleted: sha256:6c7171b141d689c4f2cb85bec056e8efa281f7d0c13d5f6ec8786fdfe0b2dacc    
Deleted: sha256:eb01d41966798251e6cf87030021b9430e39be92152d1b699b862ce7ffd392b6    
Deleted: sha256:d3d01e57b3ff262d299d2fc86ee4e6243464aace5f0bb127529ec0b7cf36bcc1    
Deleted: sha256:48292444284d3251871963192eb99ff82e3929af68426b43edf7bfc4dae1580d    
Deleted: sha256:6ca882a31a79adbdf39412feee05487de45617f70711389b94145eb1475b2146    

You can write a simple script to start and stop PolarDB (Note that the ID is changed to your own container ID).

vi ~/polardb

#!/bin/bash

case "$1" in
  start)
    docker start 1373488a35ab
    sleep 3
    docker exec -ti 1373488a35ab bash
    ;;
  stop)
    docker stop 1373488a35ab
    sleep 3
    docker ps -a
    ;;
  *)
    echo "polardb start|stop"
    ;;
esac

chmod 500 ~/polardb

Query docker logs:

docker logs --details polardb_pg_htap

Query the image dockerfile:

IT-C02YW2EFLVDL:~ digoal$ docker history polardb/polardb_pg_local_instance:htap
IMAGE          CREATED         CREATED BY                                      SIZE      COMMENT
5299da4278f5   4 weeks ago     ENTRYPOINT ["/bin/sh" "-c" "~/tmp_basedir_po…   0B        buildkit.dockerfile.v0
<missing>      4 weeks ago     RUN /bin/sh -c sudo chmod -R 700 /home/postg…   4.96GB    buildkit.dockerfile.v0
<missing>      4 weeks ago     RUN /bin/sh -c sudo chown -R postgres:postgr…   112B      buildkit.dockerfile.v0
<missing>      4 weeks ago     COPY /home/postgres/tmp_replica_dir_polardb_…   32.3MB    buildkit.dockerfile.v0
<missing>      4 weeks ago     COPY /home/postgres/tmp_replica_dir_polardb_…   32.2MB    buildkit.dockerfile.v0
<missing>      4 weeks ago     COPY /home/postgres/tmp_master_dir_polardb_p…   32.9MB    buildkit.dockerfile.v0
<missing>      4 weeks ago     COPY /home/postgres/tmp_datadir_polardb_pg_1…   4.6GB     buildkit.dockerfile.v0
<missing>      4 weeks ago     COPY /home/postgres/tmp_basedir_polardb_pg_1…   268MB     buildkit.dockerfile.v0
<missing>      4 weeks ago     LABEL maintainer=mrdrivingduck@gmail.com        0B        buildkit.dockerfile.v0
<missing>      4 weeks ago     USER postgres                                   0B        buildkit.dockerfile.v0
<missing>      4 weeks ago     RUN /bin/sh -c echo "modify conf" &&     mkd…   904B      buildkit.dockerfile.v0
<missing>      4 weeks ago     WORKDIR /home/postgres                          0B        buildkit.dockerfile.v0
<missing>      4 weeks ago     RUN /bin/sh -c echo "create default user" &&…   361kB     buildkit.dockerfile.v0
<missing>      4 weeks ago     ENV USER_NAME=postgres                          0B        buildkit.dockerfile.v0
<missing>      4 weeks ago     RUN /bin/sh -c curl -fsSL https://rpm.nodeso…   143MB     buildkit.dockerfile.v0
<missing>      4 weeks ago     RUN /bin/sh -c cd /usr/local &&     wget --n…   45.7MB    buildkit.dockerfile.v0
<missing>      4 weeks ago     ENV PFSD_VERSION=pfsd4pg-release-1.2.42-2022…   0B        buildkit.dockerfile.v0
<missing>      4 weeks ago     ENV OPENSSL_VERSION=OpenSSL_1_1_1k              0B        buildkit.dockerfile.v0
<missing>      4 weeks ago     ENV ZLOG_VERSION=1.2.14                         0B        buildkit.dockerfile.v0
<missing>      4 weeks ago     ENV GITHUB_PROXY=                               0B        buildkit.dockerfile.v0
<missing>      4 weeks ago     RUN /bin/sh -c yum install -y         git lc…   166MB     buildkit.dockerfile.v0
<missing>      4 weeks ago     RUN /bin/sh -c yum install -y         libicu…   128MB     buildkit.dockerfile.v0
<missing>      4 weeks ago     RUN /bin/sh -c yum install -y         devtoo…   650MB     buildkit.dockerfile.v0
<missing>      4 weeks ago     RUN /bin/sh -c rpmkeys --import file:///etc/…   305MB     buildkit.dockerfile.v0
<missing>      4 weeks ago     RUN /bin/sh -c sed -i 's/override_install_la…   1.02kB    buildkit.dockerfile.v0
<missing>      4 weeks ago     CMD ["/bin/sh" "-c" "bash"]                     0B        buildkit.dockerfile.v0
<missing>      4 weeks ago     LABEL maintainer=mrdrivingduck@gmail.com        0B        buildkit.dockerfile.v0
<missing>      16 months ago   /bin/sh -c #(nop)  CMD ["/bin/bash"]            0B        
<missing>      16 months ago   /bin/sh -c #(nop)  LABEL org.label-schema.sc…   0B        
<missing>      16 months ago   /bin/sh -c #(nop) ADD file:b3ebbe8bd304723d4…   204MB     


IT-C02YW2EFLVDL:~ digoal$ docker history --no-trunc polardb/polardb_pg_local_instance:htap
IMAGE                                                                     CREATED         CREATED BY   SIZE      COMMENT
sha256:5299da4278f55b9a62bc08bec4171166d6270f1e3702efb43d9d144837d2cb59   4 weeks ago     ENTRYPOINT ["/bin/sh" "-c" "~/tmp_basedir_polardb_pg_1100_bld/bin/pg_ctl -D ~/tmp_master_dir_polardb_pg_1100_bld start &&     ~/tmp_basedir_polardb_pg_1100_bld/bin/pg_ctl -D ~/tmp_replica_dir_polardb_pg_1100_bld1 start &&     ~/tmp_basedir_polardb_pg_1100_bld/bin/pg_ctl -D ~/tmp_replica_dir_polardb_pg_1100_bld2 start &&     bash"]    
   

IT-C02YW2EFLVDL:~ digoal$ docker run -d -it --cap-add=SYS_PTRACE --privileged=true --name dbas polardb/polardb_pg_local_instance:htap "; /usr/lib/systemd/systemd"
422eef87c47a93fb31791973c1be3c82b3ba3148db9bb8f862846ab1e4aa4983


IT-C02YW2EFLVDL:~ digoal$ docker exec -it dbas /bin/bash

[postgres@422eef87c47a ~]$ ps -ewf|grep systemd
postgres     1     0  0 09:11 pts/0    00:00:00 /bin/sh -c ~/tmp_basedir_polardb_pg_1100_bld/bin/pg_ctl -D ~/tmp_master_dir_polardb_pg_1100_bld start &&     ~/tmp_basedir_polardb_pg_1100_bld/bin/pg_ctl -D ~/tmp_replica_dir_polardb_pg_1100_bld1 start &&     ~/tmp_basedir_polardb_pg_1100_bld/bin/pg_ctl -D ~/tmp_replica_dir_polardb_pg_1100_bld2 start &&     bash ; /usr/lib/systemd/systemd

Create a child image to overwrite the parent image ENTRYPOINT

vi Dockerfile


FROM polardb/polardb_pg_local_instance:htap
ENTRYPOINT ["/usr/lib/systemd/systemd", "&&", "/bin/sh", "-c", "~/tmp_basedir_polardb_pg_1100_bld/bin/pg_ctl -D ~/tmp_master_dir_polardb_pg_1100_bld start &&     ~/tmp_basedir_polardb_pg_1100_bld/bin/pg_ctl -D ~/tmp_replica_dir_polardb_pg_1100_bld1 start &&     ~/tmp_basedir_polardb_pg_1100_bld/bin/pg_ctl -D ~/tmp_replica_dir_polardb_pg_1100_bld2 start "]

sudo docker build -t polardb/polardb_pg_local_instance:new .

docker run -d -it --cap-add=SYS_PTRACE --privileged=true --name dbas  polardb/polardb_pg_local_instance:new 
OR
docker run -d -it --cap-add=SYS_PTRACE --cap-add SYS_ADMIN --name dbas  polardb/polardb_pg_local_instance:new 
This issue should be fixed now. Please, don't use --privileged; using --privileged disables all protection that containers provide. Using --cap-add SYS_ADMIN is sufficient in current versions of Docker;


IT-C02YW2EFLVDL:~ digoal$ docker ps -a --no-trunc
CONTAINER ID    IMAGE   COMMAND  CREATED         STATUS          PORTS     NAMES
a2cd81b41cf15aa18a66a3beef01c7a9a2db7bb5e5824ca45d6f628d46a0a52f   polardb/polardb_pg_local_instance:new    "/usr/lib/systemd/systemd && /bin/sh -c '~/tmp_basedir_polardb_pg_1100_bld/bin/pg_ctl -D ~/tmp_master_dir_polardb_pg_1100_bld start &&     ~/tmp_basedir_polardb_pg_1100_bld/bin/pg_ctl -D ~/tmp_replica_dir_polardb_pg_1100_bld1 start &&     ~/tmp_basedir_polardb_pg_1100_bld/bin/pg_ctl -D ~/tmp_replica_dir_polardb_pg_1100_bld2 start '"   
2 minutes ago   
Up 2 minutes              
dbas


IT-C02YW2EFLVDL:~ digoal$ docker logs dbas
[!!!!!!] Failed to mount API filesystems, freezing.
-- The base image needs to package systemd.
-- For more information about repackaging systemd, see Systemd Integration.
https://hub.docker.com/_/centos/


docker exec -it dbas /bin/bash

[postgres@a2cd81b41cf1 ~]$ ps -p 1 -o comm=
systemd

ps -ewf|grep systemd

postgres     1     0  0 07:08 pts/0    00:00:00 /usr/lib/systemd/systemd && /bin/sh -c ~/tmp_basedir_polardb_pg_1100_bld/bin/pg_ctl -D ~/tmp_master_dir_polardb_pg_1100_bld start &&     ~/tmp_basedir_polardb_pg_1100_bld/bin/pg_ctl -D ~/tmp_replica_dir_polardb_pg_1100_bld1 start &&     ~/tmp_basedir_polardb_pg_1100_bld/bin/pg_ctl -D ~/tmp_replica_dir_polardb_pg_1100_bld2 start 

exit

docker stop dbas
docker rm dbas
docker rmi polardb/polardb_pg_local_instance:new 

Reference

https://www.jianshu.com/p/d3cd36c97abc

0 1 0
Share on

digoal

278 posts | 24 followers

You may also like

Comments