diff --git a/README.md b/README.md index 650ffa6..eb52385 100644 --- a/README.md +++ b/README.md @@ -2,7 +2,97 @@ ------------------ -# 使い方 +# 使い方 - 'Docker compose' + +## 1) 準備 + +* Use by DockerHub `kartoza/postgis:9.6-2.4` + +* Use by DockerHub `dpage/pgadmin4` + +- 空のディレクトリを作成 + - `$ mkdir ./dbdata` + +## 2) PostGIS(osmdb) データベースとpgadmin4を立ち上げる + +- YMLファイルを作成 + - `$ vi docker-compose.yml` + +``` +version: '3' +services: + postgis: + image: kartoza/postgis:9.6-2.4 + container_name: osmdb + restart: always + volumes: + - dbdata:/var/lib/postgresql/ + ports: + - 5432:5432 + environment: + POSTGRES_USER: alex + POSTGRES_PASS: password + POSTGRES_DBNAME: osmdb + ALLOW_IP_RANGE: 0.0.0.0/0 + pgadmin4: + image: dpage/pgadmin4 + container_name: pgadmin4 + ports: + - 80:80 + environment: + PGADMIN_DEFAULT_EMAIL: pgadmin@mail.com + PGADMIN_DEFAULT_PASSWORD: password +volumes: + dbdata: +``` + +## 3) 起動 + +- `$ docker-compose up -d` + + ``` + Creating network "postgis_default" with the default driver + Creating volume "postgis_dbdata" with default driver + Creating pgadmin4 ... + Creating osmdb ... + Creating pgadmin4 + Creating osmdb ... done + ``` + +- `$ docker-compose ps` + + +## 4) "pgAdmin4"で接続を確認する + +4-1) webブラウザ: [http://localhost](http://localhost) + +4-2) pgAdmin4 : Login + + * [http://localhost](http://localhost) + * userid: `pgadmin@mail.com` + * password: `password` + +4-3) pgAdmin4 : 接続 / Connection + + * host name: `172.17.0.1` + * port: `5432` + * database admin: `postgres` + * user name: `alex` + * password: `password` + + +## 5) 停止 + +- 通常停止 + - `$ docker-compose down` + +- 停止(DBデータ削除) + - `$ docker-compose down -v` + + +------------------ + +# 使い方 - **pure docker** ## PostGIS(osmdb) データベースを立ち上げる @@ -16,7 +106,7 @@ 3) `mkdir $HOME/pg_data` -4) `docker run --name=osmdb -m 2g -d -e POSTGRES_USER=alex -e POSTGRES_PASS=password -e POSTGRES_DBNAME=osmdb -e ALLOW_IP_RANGE=0.0.0.0/0 -p 5432:5432 -v $HOME/pg_data:/var/lib/postgresql --restart=always kartoza/postgis:9.6-2.4` +4) `docker run --name=osmdb -m 2g -d -e POSTGRES_USER=alex -e POSTGRES_PASS=password -e POSTGRES_DBNAME=osmdb -e ALLOW_IP_RANGE=0.0.0.0/0 -p 5432:5432 -v $HOME/pg_data:/var/lib/postgresql --restart=always kartoza/postgis:9.6-2.4` | param | comment | |------------------------------|-----------| @@ -34,7 +124,7 @@ $ docker pull kartoza/postgis:9.6-2.4 $ mkdir $ mkdir $HOME/pg_data -$ docker run -m 2g --name=osmdb -d -e POSTGRES_USER=alex -e POSTGRES_PASS=password -e POSTGRES_DBNAME=osmdb -e ALLOW_IP_RANGE=0.0.0.0/0 -p 5432:5432 -v $HOME/pg_data:/var/lib/postgresql --restart=always kartoza/postgis:9.6-2.4 +$ docker run -m 2g --name=gisdb -d -e POSTGRES_USER=alex -e POSTGRES_PASS=password -e POSTGRES_DBNAME=osmdb -e ALLOW_IP_RANGE=0.0.0.0/0 -p 5432:5432 -v $HOME/pg_data:/var/lib/postgresql --restart=always kartoza/postgis:9.6-2.4 $ ``` @@ -59,7 +149,7 @@ 4) pgAdmin4 : 接続 / Connection - * host name: `localhost` + * host name: `172.17.0.1` * port: `5432` * database admin: `postgres` * user name: `alex` @@ -80,8 +170,10 @@ 6. osm2pgsql ``` -echo '*:*:*:alex:password' > ~/.pgpass -chmod 600 ~/.pgpass +echo '*:*:*:alex:password' > /root/.pgpass +echo '*:*:*:postgres:password' >> /root/.pgpass +echo '*:*:*:gisuser:password' >> /root/.pgpass +chmod 600 /root/.pgpass ``` 91. stop pgAdmin4 `docker stop stupefied_poitras` diff --git a/docker-compose.yml b/docker-compose.yml new file mode 100644 index 0000000..1ea5c37 --- /dev/null +++ b/docker-compose.yml @@ -0,0 +1,16 @@ +version: '3' +services: + postgis: + image: kartoza/postgis:9.6-2.4 + container_name: osmdb + volumes: + - dbdata:/var/lib/postgresql/ + ports: + - 5432:5432 + environment: + POSTGRES_USER: alex + POSTGRES_PASS: password + POSTGRES_DBNAME: osmdb + ALLOW_IP_RANGE: 0.0.0.0/0 +volumes: + dbdata: diff --git a/pgpass.txt b/pgpass.txt new file mode 100755 index 0000000..6f96e74 --- /dev/null +++ b/pgpass.txt @@ -0,0 +1,3 @@ +*:*:*:alex:password +*:*:*:postgres:password +*:*:*:gisuser:password diff --git a/start.sh b/start.sh index 2dbb069..1946e03 100755 --- a/start.sh +++ b/start.sh @@ -4,6 +4,6 @@ -e POSTGRES_DBNAME=osmdb \ -e ALLOW_IP_RANGE=0.0.0.0/0 \ -p 5432:5432 \ --v pg_data:/var/lib/postgresql \ +-v ${pwd}/pg_data:/var/lib/postgresql \ --name postgis kartoza/postgis:9.6-2.4