Wednesday, July 6, 2016

How to deploy WSO2 API Manager with MySQL database and nginx using docker

Install Docker. Please follow the instructions below. Original document for instructions available here( But only change is we need to change version to 1.7.0 as i listed here.
  1. Install Docker Engine:
  2. The Docker Toolbox installation includes both Engine and Compose, so Mac and Windows users are done installing. Others should continue to the next step.
  3. Go to the Compose repository release page on GitHub.
  4. Follow the instructions from the release page and run the curl command, which the release page specifies, in your terminal.
    Note: If you get a “Permission denied” error, your /usr/local/bin directory probably isn’t writable and you’ll need to install Compose as the superuser. Run sudo -i, then the two commands below, then exit.
    The following is an example command illustrating the format:
    curl -L`uname -s`-`uname -m` > /usr/local/bin/docker-compose
    If you have problems installing with curl, see Alternative Install Options.
  5. Apply executable permissions to the binary:
    $ chmod +x /usr/local/bin/docker-compose
  6. Optionally, install command completion for the bash and zsh shell.
  7. Test the installation.
    $ docker-compose --version
    docker-compose version: 1.7.0

Add following entry to /etc/hosts in host machine as follows. api-manager
Then we can refer api-manager url from host machine and access API Manager deployment. We are going to have simple deployment with following components.
  • One WSO2 API Manager 1.10 instance.
  • Nginx instance to act as proxy.
  • One MySQL instance to store data.

See following docker compose file with server definitions.

version: '2'
    container_name: apim_rdbms
        context: .
        dockerfile: database/Dockerfile
    container_name: api-manager
      context: .
      dockerfile: api-manager/Dockerfile
      - SLEEP=100
      - nginx:api-manager
    container_name: nginx
      context: .
      dockerfile: nginx/Dockerfile
      - SLEEP=100
      - "444:9443"
      - "81:9763"
      - "8280:8280"
      - "8243:8243"

First we need to have docker base image for API Manager and you have to create it using docker or can download from docker repos. If you downloaded then you can import it as follows to local repository. You need to follow same steps to nginx and mysql servers as well(these base images will available on docker public repo). 

Import image.
docker load < wso2am.tgz
List loaded images.
docker images 
REPOSITORY                                       TAG                 IMAGE ID            CREATED             SIZE   latest              a71fcdc506aa        18 minutes ago      188 MB
sanjeewa-ubuntu                                  latest              a71fcdc506aa        18 minutes ago      188 MB                1.10.0              7ae5de86a076        3 weeks ago         1.032 GB                 latest              2fede7433e44        4 weeks ago         182.8 MB               latest              0530ac8e24b0        9 weeks ago         228.8 MB                latest              b72889fa879c        11 weeks ago        188 MB                 5.5                 783151ba5745        11 weeks ago        256.9 MB

Now you have API Manager image in repo and can use it for your deployments. Complete deployment pattern is available here and you need to download it. Then unzip content to directory. Then you will see following content.

As you can see we have all configuration files and data required for this deployment. When we start instances these config files and artifacts will replaced in original images.

Build and start deployment
docker-compose up --build
Stop running deployment.
docker-compose down 

Cleanup files.
docker rm -f $(docker ps -qa)

Then access created instance from host machine by accessing following URL.

Then you can login to publisher, store and management console to perform user operations. If you need to setup complex deployment you can design it and create docker compose file in same way we discussed here.

No comments:

Post a Comment