Custom container background
Due to the need of recent product development, I have written a project including download and upload, which can support. SHP format files. Because we use postgresQL database, need to compile PostGIS, this process is a bit complicated, need to configure some other plug-ins, if you need to use a new server, need to configure again, time-consuming. In order to avoid this problem, it is thought to use docker configuration, plug and play, save time and effort.
Why configure containers in Debian
Debian is generally a much more stable operating system for servers than Ubuntu. As stable as you can say. The debian system as a whole, as long as there are no logic flaws at the application level, is basically unbreakable and does not need to be rebooted all year round (this is an exaggeration, of course, but it does not overstate its stability). Debian whole system base core is very small, not only stable, but also takes up small disk space, small memory. CentOS is a bit bigger than Debian. With 128M VPS, Debian runs smoothly, while CentOS is a bit more difficult. So we chose a Debian image to configure the container.
Install the docker
Docker installation documents online many, here will not be repeated, you can see this website, I think it is written in detail. Very comprehensive, very clear and very friendly to beginners. Docker – tutorial
Access to the mirror
Once Docker starts, you need to get the image.
## Check whether the debian image was pulled successfully docker images or Docker image lsCopy the code
Configure the DockerFile file
In a directory, create a Dockerfile file
mkdir dockerFolder
cd dockerFolder
touch Dockerfile
vim Dockerfile
Copy the code
Edit the Dockerfile and place the following code in the Dockerfile
FROM debian RUN set -x; buildDeps='gcc libc6-dev make wget' \ && apt-get update \ && apt-get install -y $buildDeps \ && apt-get install -y Xz - utils \ && CD/usr/local / && wget https://nodejs.org/dist/v14.16.0/node-v14.16.0-linux-x64.tar.xz \ && tar xf Xz \ &&ln -sf /usr/local/node-v14.16.0-linux-x64/bin/npm /usr/local/bin/npm \ &&ln -sf /usr/local/bin/npm \ &&ln -sf /usr/local/bin/npm \ &&ln -sf /usr/local/node-v14.16.0-linux-x64/bin/node /usr/local/bin/node COPY gdal-2.1.1.tar. gz /usr/local/copy Geos-3.6.2.tar. bz2 /usr/local/copy json-c 0.13.1.tar.gz /usr/local/copy postgis-3.0.1.tar.gz /usr/local/copy Postgresql-12.0.tar. gz /usr/local/copy proj-5.1.0.tar.gz /usr/local/copy protobuf-c 1.3.3.tar.gz /usr/local/copy Protobuf-v3.5.0.tar. gz /usr/local/run CD /usr/local \ &&tar -zxvf postgresql-12.0.tar.gz \ &&cd postgresql-12.0 \ && Apt-get install -y libreadline-dev ## centos yum -y install readline-devel && apt-get install zlib1g.dev \ && ./configure --prefix=/usr/local/pgsql \ && make \ && Make install \ RUN CD /usr/local \ && apt-get install -y bzip2 \ && apt-get install g++ && tar -jxvf geos-3.6.2.tar.bz2 \ &&cd geos-3.6.2 \ &&. /configure --prefix=/usr/local/geos \ && make \ && make install \ RUN CD /usr/local \ && tar -zxvf proj-5.1.0.tar.gz \ && CD proj-5.1.0 \ &&./configure --prefix=/usr/local/proj \ && make \ && make install \ RUN CD /usr/local \ && tar -zxvf json-c-0.13.1.tar.gz \ && CD json-c-0.13.1 \ && apt-get install -y autoconf automake libtool \ && ./configure --prefix=/usr/local/json-c \ && make \ && make install \ RUN cd /usr/local \ && tar -zxvf Gdal-2.3.1.tar. gz \ && CD gdal-2.3.1 \ &&./configure --prefix=/usr/local/ gdal-&& make \ && make install \ RUN CD /usr/local \ &&tar -zxvf protobuf-v3.5.0.tar.gz \ &&cd protobuf-3.5.0\ &&apt-get install -y autoconf automake libtool \ && apt-get install -y curl \ && apt-get install -y unzip \ && sh ./autogen.sh \ && ./configure --prefix=/usr/local/protobuf \ && make \ && make install \ RUN CD /usr/local/tar -zxvf protobuf-c-1.3.3.tar.gz \ && CD protobuf - c - 1.3.3 \ && apt - get the install - y PKG - config \ && export PKG_CONFIG_PATH = / usr/local/protobuf/lib/pkgconfig \ && ./configure --prefix=/usr/local/protobuf-c \ && make \ && make install \ RUN cd /usr/local \ && tar -zxvf Postgis-3.0.1.tar. gz \ && CD postgis-3.0.1 \ && apt-get install -y libxml2-dev \ &&./configure --with-pgconfig=/usr/local/pgsql/bin/pg_config --with-geosconfig=/usr/local/geos/bin/geos-config --with-projdir=/usr/local/proj --with-gdalconfig=/usr/local/gdal/bin/gdal-config --with-protobufdir=/usr/local/protobuf-c --with-jsondir=/usr/local/json-c \ && make \ && make install \ /usr/local/pgsql/bin RUN ln -sf /usr/local/pgsql/bin/initdb /usr/bin/initdb \ && ln -sf /usr/local/geos/lib/libgeos_c.so.1 /usr/local/pgsql/lib/ \ && adduser postgres \ && mkdir /usr/local/pgsql/data \ && chown postgres /usr/local/pgsql/dataCopy the code
1: Our project uses the egg.js framework, so node is configured in the first part. Please configure other languages by yourself.
2: In the second part, I used the COPY command to put the compressed package into the container. I can also directly download the package by using the wget method with the RUN command. However, the download process is a little slow, and if there is an error, I will repeat the download again, which takes a lot of time. COPY into the container with the COPY command. *
3: Because the content of Dockerfile is long, it is recommended that novices configure the content one paragraph at a time to avoid unnecessary pits.
Run the DockerFile file
In the directory where the Dockerfile file resides, execute the file
Docker build -t debian. Docker build -t debian. Docker build -t debian.Copy the code
Enter the Debian container
docker run -it debian /bin/bash
su postgres
Copy the code
The configuration is successful if you can enter the Postgres user.
Package the Debian container
docker save -o debian.tar debian
Copy the code
Generate a tar package that can be used in any environment
Load the image in the new environment
docker load -i debian.tar
Copy the code
Once loaded successfully, you are ready to use the image.
note
Recommend a very useful coordinate system conversion function, based on PG+PostGIS conversion coordinate system function. Support all kinds of coordinate system, point, line and plane conversion coordinate system conversion function