This is an automated email from the ASF dual-hosted git repository. wenming pushed a commit to branch master in repository https://gitbox.apache.org/repos/asf/incubator-apisix-docker.git
The following commit(s) were added to refs/heads/master by this push: new f704bc7 fix #8 specify ip with network instead of host network (#53) f704bc7 is described below commit f704bc77111ea95bc4ac7f999be9939931c4f42c Author: kv <gxt...@163.com> AuthorDate: Sat May 16 11:38:25 2020 +0800 fix #8 specify ip with network instead of host network (#53) --- README.md | 61 ++++++++++++++++++++++++++++++++++------- example/README.md | 8 +++--- example/apisix_conf/config.yaml | 2 +- example/docker-compose.yml | 28 +++++++++++++------ 4 files changed, 76 insertions(+), 23 deletions(-) diff --git a/README.md b/README.md index 22b9a02..01c8021 100644 --- a/README.md +++ b/README.md @@ -16,13 +16,31 @@ docker build -t apisix:master-alpine -f alpine/Dockerfile alpine ``` -## Run etcd server +## Run with docker + +### Create a network `apisix` + +``` +docker network create \ + --driver=bridge \ + --subnet=172.18.0.0/16 \ + --ip-range=172.18.5.0/24 \ + --gateway=172.18.5.254 \ + apisix +``` + +### Run etcd server with `apisix` network + + +Specify ip `172.18.5.10` ``` docker run -it --name etcd-server \ -v `pwd`/example/etcd_conf/etcd.conf.yml:/opt/bitnami/etcd/conf/etcd.conf.yml \ -p 2379:2379 \ -p 2380:2380 \ +--network apisix \ +--ip 172.18.5.10 \ --env ALLOW_NONE_AUTHENTICATION=yes bitnami/etcd:3.3.13-r80 ``` @@ -31,23 +49,46 @@ docker run -it --name etcd-server \ > 1. windows OS use absolute paths to hang in the configuration file. > 2. e.g:windows dir path `E:\GitHub\docker-apisix `,configuration file hang > path is `-v > /e/github/docker-apisix/example/etcd_conf/etcd.conf.yml:/opt/bitnami/etcd/conf/etcd.conf.yml` -## Run Apache APISIX server +### Run Apache APISIX server You need etcd docker to work with Apache APISIX. You can refer to [the docker-compose example](example/README.md). Or you can run APISIX with Docker directly(Docker name is test-api-gateway): + +Check or Modify etcd address to `http: //172.18.5.10:2379` in `pwd` / example / apisix_conf / config.yaml: /usr/local/apisix/conf/config.yaml + ``` docker run --name test-api-gateway \ --v `pwd`/example/apisix_conf/config.yaml:/usr/local/apisix/conf/config.yaml \ --v `pwd`/example/apisix_log:/usr/local/apisix/logs \ --p 8080:9080 \ --p 8083:9443 \ --d apache/apisix + -v `pwd`/example/apisix_conf/config.yaml:/usr/local/apisix/conf/config.yaml \ + -v `pwd`/example/apisix_log:/usr/local/apisix/logs \ + -p 9080:9080 \ + -p 9443:9443 \ + --network apisix \ + --ip 172.18.5.11 \ + -d apache/apisix ``` > Note: > -> 1. mac OS not supports `host` network mode, so Linux is recommended. -> -> 2. windows OS use absolute paths to hang in the configuration file and log dir. +> 1. windows OS use absolute paths to hang in the configuration file and log dir. > + + +### Have a test + +Test with admin api + +e.g. Get route list, should be return + +``` +curl http://127.0.0.1:9080/apisix/admin/routes/ +... +{"node":{"createdIndex":4,"modifiedIndex":4,"key":"\/apisix\/routes","dir":true},"action":"get"} +``` + +### Clean +``` +docker rm test-api-gateway +docker rm etcd-server +docker network rm apisix +``` \ No newline at end of file diff --git a/example/README.md b/example/README.md index 48d34b7..bf54b6d 100644 --- a/example/README.md +++ b/example/README.md @@ -12,7 +12,7 @@ curl http://127.0.0.1:9080/apisix/admin/services/1 -H 'X-API-KEY: edd1c9f034335f "upstream": { "type": "roundrobin", "nodes": { - "127.0.0.1:9081": 1 + "172.18.5.12:8000": 1 } } }' @@ -22,7 +22,7 @@ curl http://127.0.0.1:9080/apisix/admin/services/2 -H 'X-API-KEY: edd1c9f034335f "upstream": { "type": "roundrobin", "nodes": { - "127.0.0.1:9082": 1 + "172.18.5.13:8000": 1 } } }' @@ -36,7 +36,7 @@ curl http://127.0.0.1:9080/apisix/admin/routes/11 -H 'X-API-KEY: edd1c9f034335f1 curl http://127.0.0.1:9080/apisix/admin/routes/12 -H 'X-API-KEY: edd1c9f034335f136f87ad84b625c8f1' -X PUT -d ' { - "uri": "/{:.*}", + "uri": "/*", "host": "web1.lvh.me", "service_id": "1" }' @@ -50,7 +50,7 @@ curl http://127.0.0.1:9080/apisix/admin/routes/21 -H 'X-API-KEY: edd1c9f034335f1 curl http://127.0.0.1:9080/apisix/admin/routes/22 -H 'X-API-KEY: edd1c9f034335f136f87ad84b625c8f1' -X PUT -d ' { - "uri": "/{:.*}", + "uri": "/*", "host": "web2.lvh.me", "service_id": "2" }' diff --git a/example/apisix_conf/config.yaml b/example/apisix_conf/config.yaml index b355e32..920a321 100644 --- a/example/apisix_conf/config.yaml +++ b/example/apisix_conf/config.yaml @@ -60,7 +60,7 @@ nginx_config: # config for render the template to genarate n - 'unix:' etcd: - host: "http://127.0.0.1:2379" # etcd address + host: "http://172.18.5.10:2379" # etcd address prefix: "/apisix" # apisix configurations prefix timeout: 1 # 1 seconds diff --git a/example/docker-compose.yml b/example/docker-compose.yml index c6a0b01..6da23b9 100644 --- a/example/docker-compose.yml +++ b/example/docker-compose.yml @@ -4,14 +4,20 @@ services: apisix: build: context: ./.. - dockerfile: alpine/Dockerfile + dockerfile: centos/Dockerfile restart: always volumes: - ./apisix_log:/usr/local/apisix/logs - ./apisix_conf/config.yaml:/usr/local/apisix/conf/config.yaml:ro depends_on: - etcd - network_mode: host + ##network_mode: host + ports: + - "9080:9080/tcp" + - "9443:9443/tcp" + networks: + apisix: + ipv4_address: 172.18.5.11 etcd: # if you are in the mainland China, please use Azure China mirror: @@ -24,28 +30,34 @@ services: environment: ETCD_DATA_DIR: /etcd_data ports: - - "127.0.0.1:2379:2379/tcp" + - "2379:2379/tcp" networks: - - apisix + apisix: + ipv4_address: 172.18.5.10 web1: image: ruby:2-alpine command: sh -c "mkdir -p /tmp/www && echo 'web1' > /tmp/www/web1.txt && ruby -run -ehttpd /tmp/www -p8000" restart: always ports: - - "127.0.0.1:9081:8000/tcp" + - "9081:8000/tcp" networks: - - apisix + apisix: + ipv4_address: 172.18.5.12 web2: image: ruby:2-alpine command: sh -c "mkdir -p /tmp/www && echo 'web2' > /tmp/www/web2.txt && ruby -run -ehttpd /tmp/www -p8000" restart: always ports: - - "127.0.0.1:9082:8000/tcp" + - "9082:8000/tcp" networks: - - apisix + apisix: + ipv4_address: 172.18.5.13 networks: apisix: driver: bridge + ipam: + config: + - subnet: 172.18.0.0/16