【docker】centos7 docker安装 postgresql+postgis 安装 jar部署 geoserver部署

离线安装docker

  1. 下载地址 : https://download.docker.com/linux/static/stable/x86_64/
  2. 选择合适的版本进行下载
  3. 复制到centos
  4. 解压
    tar -xvf (docker的tar包)
    
  5. 将解压出来的docker文件内容移动到/usr/bin目录下
    cp docker/* /usr/bin
    
  6. 将docker注册为service
    vim /etc/systemd/system/docker.service
    
    内容:
    [Unit]
    Description=Docker Application Container Engine
    Documentation=https://docs.docker.com
    # BindsTo=containerd.service
    # After=network-online.target firewalld.service containerd.service
    After=network-online.target firewalld.service
    Wants=network-online.target
    # Requires=docker.socket
    
    [Service]
    Type=notify
    # the default is not to use systemd for cgroups because the delegate issues still
    # exists and systemd currently does not support the cgroup feature set required
    # for containers run by docker
    # ExecStart=/usr/bin/dockerd -H fd:// --containerd=/run/containerd/containerd.sock
    ExecStart=/usr/bin/dockerd
    ExecReload=/bin/kill -s HUP $MAINPID
    TimeoutSec=0
    RestartSec=2
    Restart=always
    
    # Note that StartLimit* options were moved from "Service" to "Unit" in systemd 229.
    # Both the old, and new location are accepted by systemd 229 and up, so using the old location
    # to make them work for either version of systemd.
    StartLimitBurst=3
    
    # Note that StartLimitInterval was renamed to StartLimitIntervalSec in systemd 230.
    # Both the old, and new name are accepted by systemd 230 and up, so using the old name to make
    # this option work for either version of systemd.
    StartLimitInterval=60s
    
    # Having non-zero Limit*s causes performance problems due to accounting overhead
    # in the kernel. We recommend using cgroups to do container-local accounting.
    LimitNOFILE=infinity
    LimitNPROC=infinity
    LimitCORE=infinity
    
    # Comment TasksMax if your systemd version does not support it.
    # Only systemd 226 and above support this option.
    # TasksMax=infinity
    
    # set delegate yes so that systemd does not reset the cgroups of docker containers
    Delegate=yes
    
    # kill only the docker process, not all processes in the cgroup
    KillMode=process
    
    [Install]
    WantedBy=multi-user.target
    
  7. 镜像
    sudo mkdir -p /etc/docker
    sudo tee /etc/docker/daemon.json <<-'EOF'
    {
      "registry-mirrors": ["https://xbreq59p.mirror.aliyuncs.com"]
    }
    EOF
    sudo systemctl daemon-reload
    sudo systemctl restart docker
    

配置容器数据卷

docker run  -v 外部目录:容器目录

离线安装java镜像

  1. 一个有网的服务器,导出镜像
    docker save java:8 -o java.tar  #将java 8的镜像导出成tar文件
    
  2. 将镜像导入离线宿主机
  3. 进行镜像读取安装
    docker load -i java.tar
    

mysql,redis这些直接docker search 进行搜索拉取安装运行即可

postgresql+postgis扩展安装

安装

  1. 拉取镜像
    # 这里我选用的版本是11.5-2.8 (对应的是11.5的postgresql ,2.8版本的postgis)
    docker pull kartoza/postgis:11.5-2.8
    
  2. 运行容器
    docker run -id --name psql -e POSTGRES_USER=这里是账号 -e POSTGRES_PASS='这里是密码' -v /home/ssystem/soft/postgresql:/var/lib/postgresql -v /home/ssystem/soft/postgresql/tmp/tmp:/tmp/tmp -p 5432:5432 -t kartoza/postgis
    

    运行参数释义:
    –name: 容器name(建议设置,设置后对容器的相关操作会简便些)
    -d: 后台运行容器,并返回容器ID;
    -i: 以交互模式运行容器,通常与 -t 同时使用;
    -e: 设置环境变量 这里设置了两个,分别是账号密码
    -v:设置容器卷目录映射
    -p:端口映射
    -t 为容器重新分配一个伪输入终端,通常与 -i 同时使用;
    最后说明是以哪个镜像运行容器

postgresql sql导出导入

导出

pg_dump -h 127.0.0.1 -p 5432 -U 这里是账号 -d 这里是数据库名 -f 这里是导出的路径

如:

pg_dump -h 127.0.0.1 -p 5432 -U postgres -d lt_postgis -f E:\postgis_backup\lt_postgis.sql

导入

psql -h 192.168.3.14  -p 5432 -U 这里是账号 -d 这里是数据库名 <导入文件的路径

如:

psql -h 192.168.3.14  -p 5432 -U postgres -d lt_postgis <E:\postgis_backup\lt_postgis.sql

jar 部署

建议提前将java环境镜像下载好

jar对应的dockerfile

FROM java:8
MAINTAINER qinlei<[email protected]>

VOLUME /tmp

RUN mkdir -p /app/start \
    && touch /etc/init.d/start.sh \
    && chmod +x /etc/init.d/start.sh \
    && echo "#!/bin/bash  " >> /etc/init.d/start.sh \
    && echo "cd /app/start " >> /etc/init.d/start.sh \
    && echo "nohup java -jar /app/start/gis.jar " >> /etc/init.d/start.sh

ADD ./start/gis.jar /app/start/gis.jar

EXPOSE 8081
ENTRYPOINT /bin/sh -c   /etc/init.d/start.sh

镜像构造,容器运行:

docker build -t gxgis .

docker run -id -p 8081:8081 -p 8972:8972 -v /home/dell/project/gaoxin/:/app --name=gxgis gxgis

geoserver部署

对应的dockerfile

FROM java:8
MAINTAINER qinlei<[email protected]>

ENV GEOSERVER_HOME /app/geoserver218

RUN mkdir -p /app/geoserver218 \
    && chmod -R +x  /app/geoserver218

ADD ./geoserver218/ /app/geoserver218/

EXPOSE 10001
ENTRYPOINT /bin/sh -c   /app/geoserver218/bin/startup.sh

构造,部署

docker build -t gserver10001 .


docker run -id -p 10001:10001 -v /home/ssystem/project/geoserver10001/geoserver218:/app/geoserver/ --name=gserver10001 gserver10001

遇到的问题

镜像搜索报错

Docker Error response from daemon read: connection refused
Docker Error response from daemon read: connection refused

解决方案:

虚拟机中添加一个DNS解析解决问题

vim /etc/resolv.conf

## 添加一行:
nameserver 114.114.114.114

你可能感兴趣的:(java,webgis,docker,postgresql,jar,geoserver)