
배치 REST API를 사용하여 Liberty Docker 컨테이너 배치
DeployService REST API를 사용하여 Docker 컨테이너의 Liberty 서버를 집합체의 멤버로서 배치할 수 있습니다.
시작하기 전에
Docker 이미지를 설치하려는 대상 호스트를 판별하십시오. 대상 호스트에 Docker를 설치하십시오. 각 대상 호스트에서 RXA 또는 SSH가 필요합니다. Liberty 집합체 조작에 대한 RXA 설정을 확인하십시오.
감시: WASdev 기사의 WebSphere Liberty 집합체를 사용하여
사내 구축형 Polyglot 환경 관리 비디오가 이 주제의 프로시저를 보완합니다.
프로시저
- Docker 이미지를 작성하십시오.
- Dockerfile을 사용하여 Liberty 이미지를 작성하십시오.
다음 Dockerfile 예가 Liberty Network Deployment 이미지를 작성할 수 있습니다. Docker 허브에서 사용 가능한 이미지는 scalingMember-1.0 같은 Network Deployment 기능에 액세스할 수 없습니다. Liberty Network Deployment 이미지를 작성하려면 이 파일을 사용하십시오. 마지막 행을 사용하여 Docker 이미지에 사용할 애플리케이션을 복사할 수 있습니다.
# # Dockerfile to create a Liberty Network Deployment image # # This Dockerfile assumes: # - The collective enabling scripts (joinMember, removeMember) will be placed in # /opt/ibm/docker in the Docker container # - WebSphere Liberty will be installed at /opt/ibm/wlp # - The WebSphere Liberty server will be "defaultServer" # (for example, /opt/ibm/wlp/usr/servers/defaultServer) # - The Docker container runs using --net=host so that no ports are explicitly # exported in this file FROM websphere-liberty # # Auto-start the Liberty server with the container # ENTRYPOINT ["/opt/ibm/wlp/bin/server", "run", "defaultServer"] # # # # Add collective 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 operating system # RUN apt-get update # # Add the additional required features # RUN installUtility install --acceptLicense scalingMember-1.0 clusterMember-1.0 collectiveMember-1.0 ADD server.xml /opt/ibm/wlp/usr/servers/defaultServer/ # # Insert your application file name. This statement copies the application # onto the Docker image. # ADD application_file /opt/ibm/wlp/usr/servers/defaultServer/dropins/참고: Docker 이미지에는 Docker 컨테이너의 멤버 서버를 집합체 제어기에 결합하는 joinMember 스크립트가 있습니다.
Docker 이미지에는 집합체에서 Docker 컨테이너에 있는 멤버 서버를 제거하는 removeMember 스크립트도 있습니다.#!/bin/bash # # Script to join a Liberty 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 - hostname of the Docker host this container resides on # # Optional: --clusterName - cluster name for the member configuration. # If specified, it adds the cluster and scaling # member features also. # # 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 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 # Invoke the collective utility /opt/ibm/wlp/bin/collective join defaultServer --host=$controllerHost --port=$controllerPort --user=$controllerUser --password=$controllerPassword --hostName=$dockerHost --createConfigFile --keystorePassword=$memberKeystorePassword --autoAcceptCertificates --genDeployVariables # Build additional config dropin snippets if [[ $clusterName = *[!\ ]* ]]; then echo \<?xml version=\"1.0\" encoding=\"UTF-8\" ?\> > /opt/ibm/wlp/usr/servers/defaultServer/cfgfeatures.xml echo \<server\> >> /opt/ibm/wlp/usr/servers/defaultServer/cfgfeatures.xml echo $'\t'\<featureManager\> >> /opt/ibm/wlp/usr/servers/defaultServer/cfgfeatures.xml echo $'\t'$'\t'\<feature\>clusterMember-1.0\</feature\> >> /opt/ibm/wlp/usr/servers/defaultServer/cfgfeatures.xml echo $'\t'$'\t'\<feature\>scalingMember-1.0\</feature\> >> /opt/ibm/wlp/usr/servers/defaultServer/cfgfeatures.xml echo $'\t'\</featureManager\> >> /opt/ibm/wlp/usr/servers/defaultServer/cfgfeatures.xml echo \</server\> >> /opt/ibm/wlp/usr/servers/defaultServer/cfgfeatures.xml echo \<?xml version=\"1.0\" encoding=\"UTF-8\" ?\> > /opt/ibm/wlp/usr/servers/defaultServer/cluster-config.xml echo \<server\> >> /opt/ibm/wlp/usr/servers/defaultServer/cluster-config.xml echo $'\t'\<clusterMember name=\"$clusterName\" /\> >> /opt/ibm/wlp/usr/servers/defaultServer/cluster-config.xml echo \</server\> >> /opt/ibm/wlp/usr/servers/defaultServer/cluster-config.xml else echo "No clusterName provided, the container will not be configured as a cluster or scaling member." fi # Move config snippets to the proper location for consumption mkdir -p /opt/ibm/wlp/usr/servers/defaultServer/configDropins/overrides mv /opt/ibm/wlp/usr/servers/defaultServer/c*.xml /opt/ibm/wlp/usr/servers/defaultServer/configDropins/overrides if [ -f /opt/ibm/wlp/usr/servers/defaultServer/user-collective-include.xml ] then cp /opt/ibm/wlp/usr/servers/defaultServer/user-collective-include.xml /opt/ibm/wlp/usr/servers/defaultServer/configDropins/overrides fi else # At least one required parameter was missing, # notify the user of 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#!/bin/bash # Script to remove a Liberty 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 - hostname of the Docker host this container resides on # # # 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 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 /opt/ibm/wlp/bin/collective remove defaultServer --host=$controllerHost --port=$controllerPort --user=$controllerUser --password=$controllerPassword --hostName=$dockerHost --autoAcceptCertificates else # At least one required parameter was missing, # notify the user of 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 - Dockerfile에서 사용할 server.xml 파일을 구성하십시오.
예:
<server description="Default Server"> <featureManager> <feature>webProfile-6.0</feature> </featureManager> <httpEndpoint id="defaultHttpEndpoint" httpPort="${memberHttpPort}" httpsPort="${memberHttpsPort}" /> </server> - 집합체 제어기 server.xml 파일에 제어기 사용자 이름과
비밀번호 및 배치 변수를 정의하는 명령문이 있는지 확인하십시오. 예를 들면,
<collectiveController user="admin" password="adminpwd" /> ... <deployVariable name="memberHttpPort" value="9090" increment="1"/> <deployVariable name="memberHttpsPort" value="9453" increment="1"/>배치 변수는 각 멤버가 대상 호스트에서 고유한 포트 번호를 가질 수 있게 하는 값을 설정해야 합니다. DeployVariable(deployVariable)을 확인하십시오.
- Docker 빌드 명령을 실행하여 이미지를 작성하십시오.
- Dockerfile, joinMember 및 removeMember 스크립트, Dockerfile에서 이름 지정된 server.xml 파일을 Docker가 설치된 컴퓨터에 복사하십시오. 파일을 동일한 디렉토리에 넣으십시오.
- 파일을 보유하는 디렉토리에서 명령 창을 여십시오.
- 이미지를 작성하는 Docker 명령을
실행하십시오.
docker build -t image_name . - 이미지 작성을 확인하십시오. 다음 명령은 작성이 성공할 때 이미지 이름을
리턴합니다.
docker images
- 옵션: Docker 이미지를 Docker 허브에 게시하십시오.
- 예를 들어 Telnet이나 SSH를 사용하여 호스트에 로그인하십시오.
- Docker 레지스트리에 로그인하십시오.
- 다음과 같은 명령을 실행하여 Docker 이미지를 레지스트리에
업로드하십시오.
docker push image_name
- Dockerfile을 사용하여 Liberty 이미지를 작성하십시오.
- 대상 Docker 호스트를 집합체 제어기에 등록하십시오.
호스트를 등록하면 집합체 제어기가 레지스트리의 Docker 이미지를 해당 호스트로 가져올 뿐 아니라 호스트의 파일, 명령 및 기타 자원에 액세스할 수 있습니다. 대상 호스트를 등록하려면 registerHost 명령을 사용하십시오. 제어기의 server.xml 파일을 조사하여 --host, --port, --user 및 --password 매개변수에 대한 값을 찾으십시오. Linux 또는 Windows 운영 체제의 대상 호스트의 경우와 같이 SSH 개인 키 파일을 사용하지 않으려면 --rpcUser 및 --rpcUserPassword 매개변수를 설정하여 운영 체제 로그인 사용자 및 비밀번호를 포함하십시오. --rpcUser에 지정된 사용자에게 대상 배치 위치에 대한 운영 체제 권한이 있어야 합니다.
wlp/bin/collective registerHost targetHost --host=controllerHost --port=controllerHTTPSPort --user=controllerAdmin --password=controllerAdminPassword --rpcUser=osUser --rpcUserPassword=osUserPassword호스트가 이미 등록된 경우에는 updateHost 명령을 사용하여 등록 정보를 재설정할 수 있습니다. 자세한 정보는 Liberty 집합체에 대해 호스트 컴퓨터 등록의 내용을 참조하십시오.
- 배치할 Docker 이미지가 배치할 Docker 호스트에서 로컬로 사용할 수 있는 대신 저장소에 저장되는 경우, 해당 레지스트리에 액세스하도록 집합체 제어기를 구성할 수 있습니다. 집합적 제어기용 Docker 레지스트리 구성을 확인하십시오.
- 사용 가능한 배치 규칙을 검토하십시오.
- 사용 가능한 배치 규칙을 리턴하는 REST API를 호출하십시오.
GET https://controller_host:controller_port/ibm/api/collective/v1/deployment/rule이 호출은 배치 규칙을 JSON 구조로 리턴합니다. 예를 들면,
{"rules": [ {"id":"Liberty Docker Rule","description":"Deploy rule for Liberty containers.","type":"docker","deployCommands":"docker run -d -e LICENSE=accept --net=host --name=${containerName} ${imageName} ; docker exec -t ${containerName} bash /opt/ibm/docker/joinMember ${containerName} --clusterName=${clusterName} --dockerHost=${wlp.deploy.host} --host=${wlp.admin.host} --port=${wlp.admin.port} --user=${wlp.admin.user} --password=${wlp.admin.password} --keystorePassword=${containerName}","undeployCommands":"docker rm ${containerName} ; docker rmi ${imageName}","startCommands":"docker start ${containerName}","stopCommands":"docker stop ${containerName}","retartCommands":" ","inputVariables":[ {"name":"containerName","type":"String","description":"Name of Liberty Docker container.","defaultValue":"${imageName}_container"}, {"name":"imageName","type":"String","description":"Name of Liberty Docker image."}, {"name":"clusterName","type":"String","description":"Name of Liberty Docker container cluster.","defaultValue":"${imageName}_cluster"} ]} - 필요한 경우, DeployRules를 제어기 구성에 추가하여 고유한 배치 규칙을 작성하십시오. 배치 규칙(deployRule)을 확인하십시오.
- 사용 가능한 배치 규칙을 리턴하는 REST API를 호출하십시오.
- Docker 이미지를 배치하십시오.
배치 규칙에는 사용할 Docker 이미지 및 작성한 컨테이너 이름 같이 조작을 위한 입력 값을 지정하는 데 사용할 수 있는 변수가 들어 있습니다. 리턴 본문에는 상태 및 결과를 요청하는 데 사용할 수 있는 토큰이 들어 있습니다.
POST https://controller_host:controller_port/ibm/api/collective/v1/deployment/deploy { "rule": "Liberty Docker Rule", "hosts": [ "myHostName" ], "variables": [ { "name":"imageName", "value":"myImageName" }, { "name":"containerName", "value":"myContainerName" }, { "name":"clusterName", "value":"myClusterName" }, { "name":"keystorePassword", "value":"thePassword" } ] }예를 들어 리턴 토큰은 {"id":3}일 수 있으며, 상태 및 결과를 가져오는 데 사용할 수 있습니다.
다음에 수행할 작업
배치 상태 및 결과를 요청하고 검토하십시오.
- 요청된 배치 조작에 대한 토큰의 목록을
가져오십시오.
GET https://controller_host:controller_port/ibm/api/collective/v1/deployment/deploy - 배치 조직의 단기 상태를 가져오십시오. {token}에 대해
4단계의 토큰을 사용하십시오. 따라서, 4단계의 {"id":3}
리턴 토큰의 경우, {token}에
대해 3을 사용하십시오.
배치 중에 API가 IN_PROGRESS를 리턴합니다.GET https://controller_host:controller_port/ibm/api/collective/v1/deployment/{token}/status
배치 후, API는 FINISHED를 리턴합니다.{"status":{"target_host":"IN_PROGRESS"}}{"status":{"target_host":"FINISHED"}} - 배치 조작의 전체 결과를 가져오십시오. {token}에 대해
4단계의 토큰을 사용하십시오. 따라서, 4단계의 {"id":3}
리턴 토큰의 경우, {token}에
대해 3을 사용하십시오.
배치가 완료된 후, 결과에 조작에 대한 정보가 들어 있습니다. 다음 예는 FINISHED의 결과를 보여줍니다.GET https://controller_host:controller_port/ibm/api/collective/v1/deployment/{token}/results{"results":[{"host_name":"target_host","status":"FINISHED","result":0}]}
- 컨테이너를
배치 취소하십시오.
POST https://controller_host:controller_port/ibm/api/collective/v1/deployment/undeploy { "host": "myHostName", "userDir":"Docker", "serverName":"myContainerName" } - 배치 취소 조작에 대한 토큰 목록을
가져오십시오.
상태 및 결과를 가져오려면 배치와 유사한 단계를 따르십시오.GET https://controller_host:controller_port/ibm/api/collective/v1/deployment/undeploy
태스크 주제
마지막 업데이트 날짜: Friday, 16 September 2016http://www14.software.ibm.com/webapp/wsbroker/redirect?version=cord&product=was-nd-dist&topic=twlp_deployservice_docker
파일 이름: twlp_deployservice_docker.html
