Para plataformas LINUXPara plataformas Windows

Dockerfile de ejemplo para una imagen de miembro Node.js

Utilice el ejemplo de Dockerfile para crear una imagen de miembro de colectivo Node.js. La imagen de Docker tiene un script joinMember que une el servidor miembro en el contenedor Docker a un controlador colectivo. La imagen de Docker también tiene un script removeMember que elimina el servidor miembro en el contenedor Docker del colectivo.

Característica estabilizada: Se ha estabilizado la gestión de procesos Node.js utilizando colectivos de Liberty . V8 es la versión final soportada de Node.js para los miembros del colectivo Liberty . Para entornos locales o de infraestructura propia, utilice contenedores Docker alojados y gestionados por IBM Cloud® Private. Para entornos alojados, utilice contenedores Docker en IBM Cloud Kubernetes Service.

Archivo Docker

Utilice el ejemplo de Dockerfile siguiente para crear una imagen del miembro de colectivo Node.js. La imagen que está disponible en IBM Container Registry no puede acceder a características de Network Deployment como scalingMember-1.0. Puede utilizar las últimas dos líneas para instalar una aplicación en la imagen de Docker.

#
# Dockerfile to create a Node.js image
#
# This Dockerfile makes the following assumptions:
# - The collectives enabling scripts (joinMember, removeMember) will be placed in
#   /opt/ibm/docker in the Docker container
# - Node.js servers are created at /root/wlpn
# - The Node.js server will be "defaultServer" (for example, /root/wlpn/defaultServer)
# - The application to install will already have its dependencies resolved by "npm install"
# - The Docker container will be run using --net=host, so that no ports are explicitly exported in this file

FROM node:4-slim

#
# Auto-start the Node.js server with the container
#
ENTRYPOINT ["/usr/local/bin/wlpn-server", "run", "defaultServer"]

#
# Add collectives enabling scripts
#
ADD joinMember /opt/ibm/docker/
RUN chmod +x /opt/ibm/docker/joinMember
ADD removeMember /opt/ibm/docker/
RUN chmod +x /opt/ibm/docker/removeMember

#
# Update the OS and JRE
#
RUN apt-get update

#
# Install APIConnect collective member
#
RUN npm install -g apiconnect-collective-member


#
# Use the following code to install an application for use onto the Docker image
#
COPY express-example-app-1.0.2.tgz /root/wlpn/
RUN wlpn-server unpack defaultServer /root/wlpn/express-example-app-1.0.2.tgz

Script joinMember

El script de la imagen de Docker joinMember une el servidor miembro del contenedor Docker a un controlador colectivo:
#!/bin/bash

#
# Script to join a Node.js Docker container to a collective controller.
#
# Required: <containerName> - positional parameter that is the name of this Docker container
#           --host - collective controller hostname
#           --port - collective controller https port
#           --user - collective controller admin user
#           --password - collective controller admin user password
#           --keystorePassword - to be used for the member keystore
#           --dockerHost - the hostname of the Docker host this container resides on
#
# Optional: --clusterName - cluster name for the member configuration. If specified, adds the cluster and scaling member features.
#


# Set initial values

containerName=$1


# Parse the command line

failure="false"

if [[ -z $1 ]]; then
    # No values received
    echo "Error: no parameters specified"
    failure="true"
else
    TEMP=`getopt --long host:,port:,user:,password:,keystorePassword:,dockerHost:,clusterName:: -- "$@"`
    eval set -- "$TEMP"
    OPTIND=-1
    
    while true ; do
        case "$1" in
           --host) controllerHost=$2; shift 2;;
           --port) controllerPort=$2; shift 2;;
           --user) controllerUser=$2; shift 2;;
           --password) controllerPassword=$2; shift 2;;
           --keystorePassword) memberKeystorePassword=$2; shift 2;;
           --dockerHost) dockerHost=$2; shift 2;;
           --clusterName) clusterName=$2; shift 2;;
           *) break;;
        esac
    done

    # Validate the required parameters
    if [[ -z "$containerName" ]]; then
        echo "Error: no containerName specified, validation suspended"
        failure="true"
    fi

    # if a containerName is not specified, bash uses the 1st "--" parameter as the containerName

    if [[ $containerName == --* ]]; then
        echo "Error: no containerName specified, validation suspended"
        failure="true"
    fi
    
    # When the positional parameter containerName fails, suspend validation reporting. getops can be incorrect.
    
    if [[ $failure == false ]]; then
        if [[ -z "${controllerHost// }" ]]; then
            echo "Error: no host specified"
            failure="true"
        fi
        if [[ -z "${controllerPort// }" ]]; then
            echo "Error: no port specified"
            failure="true"
        fi
        if [[ -z "${controllerUser// }" ]]; then
            echo "Error: no user specified"
            failure="true"
        fi
        if [[ -z "${controllerPassword// }" ]]; then
            echo "Error: no password specified"
            failure="true"
        fi
        if [[ -z "${memberKeystorePassword// }" ]]; then
            echo "Error: no keystorePassword specified"
            failure="true"
        fi
        if [[ -z "${dockerHost// }" ]]; then
            echo "Error: no dockerHost specified"
            failure="true"
        fi
    fi
fi

if [[ $failure == false ]]; then
    # Create the env.properties file for the Liberty Docker member

    echo containerName=$containerName > /opt/ibm/docker/env.properties
    echo containerHost=$dockerHost >> /opt/ibm/docker/env.properties


    # Run the join operation

    if [[ $clusterName = *[!\ ]* ]]; then
        wlpn-collective join defaultServer --host=$controllerHost --port=$controllerPort --user=$controllerUser --password=$controllerPassword --keystorePassword=$memberKeystorePassword --autoAcceptCertificates --hostName=$dockerHost --clusterName=$clusterName --genDeployVars
    else
        echo "No clusterName provided. The container will not be configured as a cluster or scaling member."
        wlpn-collective join defaultServer --host=$controllerHost --port=$controllerPort --user=$controllerUser --password=$controllerPassword --keystorePassword=$memberKeystorePassword --autoAcceptCertificates --hostName=$dockerHost --genDeployVars 
    fi
else
    # At least one required parameter is missing. Provide the correct syntax.
    printf "Usage:  joinMember <containerName> \n\t--host <controller host> \n\t--port <controller https port> \n\t--user <controller user> \n\t--password <controller password> \n\t--keystorePassword <member keystore password> \n\t--dockerHost <hostname of the Docker host> \n\t[--clusterName <cluster name for the member>]\n"
fi

Script removeMember

El script de la imagen de Docker removeMember elimina el servidor miembro del contenedor Docker de un controlador colectivo:
#!/bin/bash

# Script to remove a StrongLoop Docker container from a collective controller.
#
# Required: <containerName> - positional parameter that is the name of this Docker container
#           --host - collective controller hostname
#           --port - collective controller https port
#           --user - collective controller admin user
#           --password - collective controller admin user password
#           --dockerHost - the hostname of the Docker host on which this container resides

# Set initial values

containerName=$1

# Parse the command line

failure="false"

if [[ -z $1 ]]; then
    # No values received
    echo "Error: no parameters specified"
    failure="true"
else
    TEMP=`getopt --long host:,port:,user:,password:,dockerHost:: -- "$@"`
    eval set -- "$TEMP"
    OPTIND=-1

    while true ; do
        case "$1" in
           --host) controllerHost=$2; shift 2;;
           --port) controllerPort=$2; shift 2;;
           --user) controllerUser=$2; shift 2;;
           --password) controllerPassword=$2; shift 2;;
           --dockerHost) dockerHost=$2; shift 2;;
           *) break;;
        esac
    done

    # Validate the required parameters
    if [[ -z "$containerName" ]]; then
        echo "Error: no containerName specified, validation suspended"
        failure="true"
    fi

    # if a containerName is not specified, bash uses the 1st "--" parameter as the containerName

    if [[ $containerName == --* ]]; then
        echo "Error: no containerName specified, validation suspended"
        failure="true"
    fi

    # When the positional parameter containerName fails, suspend validation reporting. getops can be incorrect.

    if [[ $failure == false ]]; then
        if [[ -z "${controllerHost// }" ]]; then
            echo "Error: no host specified"
            failure="true"
        fi
        if [[ -z "${controllerPort// }" ]]; then
            echo "Error: no port specified"
            failure="true"
        fi
        if [[ -z "${controllerUser// }" ]]; then
            echo "Error: no user specified"
            failure="true"
        fi
        if [[ -z "${controllerPassword// }" ]]; then
            echo "Error: no password specified"
            failure="true"
        fi
        if [[ -z "${dockerHost// }" ]]; then
            echo "Error: no dockerHost specified"
            failure="true"
        fi
    fi
fi

    # Invoke the collective utility
if [[ $failure == false ]]; then

    wlpn-collective remove defaultServer --host=$controllerHost --port=$controllerPort --user=$controllerUser --password=$controllerPassword --hostName=$dockerHost --autoAcceptCertificates

else
    # At least one required parameter was missing. Provide the correct syntax.
    printf "Usage:  removeMember <containerName> \n\t--host=<controller host> \n\t--port=<controller https port> \n\t--user=<controller user> \n\t--password=<controller password> \n\t--dockerHost=<docker host> \n"
fi