Docker实践2:安装Docker及weblogic镜像

安装Docker

以root登录,运行

vi /etc/yum.repos.d/public-yum-ol6.repo,添加如下段落

[ol6_addons]
name=Oracle Linux $releasever Add ons ($basearch)
baseurl=http://public-yum.oracle.com/repo/OracleLinux/OL6/addons/$basearch/
gpgkey=file:///etc/pki/rpm-gpg/RPM-GPG-KEY-oracle
gpgcheck=1
enabled=1

 

运行yum install docker

 

在运行过程中因为网络缓慢,可能出现退出情况,再运行一遍,如果遇到yum提示

another app is currently holding the yum lock;waiting for it to exit

可能是系统自动升级正在运行,yum在锁定状态中。
可以通过强制关掉yum进程:
#rm -f /var/run/yum.pid

完成后运行service start docker.

 

# chkconfig docker on

service docker status
docker (pid  9044) is running...

添加能直接运行docker权限的用户

# groupadd docker

# service docker restart

# usermod -a -G docker <your_user>

 

 

将git构建代码拿到本地

# yum install git

切换回weblogic用户,运行
$ git clone https://github.com/oracle/docker.git

如果网络比较慢的话再来一遍。


Build jre8

docker build -t oracle/serverjre:8 .

[weblogic@k8s-node-1 java-8]$ sudo docker build -t oracle/serverjre:8 .
Sending build context to Docker daemon 59.88 MB
Step 1 : FROM oraclelinux:7-slim
Trying to pull repository docker.io/library/oraclelinux ...
7-slim: Pulling from docker.io/library/oraclelinux
1f5b026b07bc: Pull complete
Digest: sha256:fdfc68d89f73172835cc2c715084b5a754cefa230b5012f7d2e8305f19acdce9
---> 442ebf722584
Step 2 : MAINTAINER Bruno Borges <bruno.borges@oracle.com>
---> Running in 2ee2b2aee1ce
---> 01dccda5f005
Removing intermediate container 2ee2b2aee1ce
Step 3 : ENV JAVA_PKG server-jre-8u*-linux-x64.tar.gz JAVA_HOME /usr/java/default
---> Running in 2e1ba8d77662
---> b92dfba19cd4
Removing intermediate container 2e1ba8d77662
Step 4 : ADD $JAVA_PKG /usr/java/
---> dd72812845da
Removing intermediate container 0419160026e2
Step 5 : RUN export JAVA_DIR=$(ls -1 -d /usr/java/*) && ln -s $JAVA_DIR /usr/java/latest && ln -s $JAVA_DIR /usr/java/default && alternatives --install /usr/bin/java java $JAVA_DIR/bin/java 20000 && alternatives --install /usr/bin/javac javac $JAVA_DIR/bin/javac 20000 && alternatives --install /usr/bin/jar jar $JAVA_DIR/bin/jar 20000
---> Running in bd4c197a5fb5
---> 8c0f2aaba6ed
Removing intermediate container bd4c197a5fb5
Successfully built 8c0f2aaba6ed



Build WebLogic Generic

进入
../docker/OracleWebLogic/dockerfiles/12.1.3目录



下载相应的文件包括server-jre-8u73-linux-x64.tar.gz,fmw_12.1.3.0.0_wls.jar,wls1213_dev_update3.zip放入
通过xmanager的xftp.

运行$ sudo sh buildDockerImage.sh -g
-d主要采用_dev的包,构件开发环境。
-g采用generic的包,也就是fmw_12.1.3.0.0_wls.jar包,构建生产环境。

[weblogic@k8s-node-1 dockerfiles]$ sudo sh buildDockerImage.sh -g
Checking if required packages are present and valid...
fmw_12.1.3.0.0_wls.jar: OK
=====================
Building image 'oracle/weblogic:12.1.3-generic' ...
Sending build context to Docker daemon 923.2 MB
Step 1 : FROM oracle/serverjre:8
---> 8c0f2aaba6ed
Step 2 : MAINTAINER Bruno Borges <bruno.borges@oracle.com>
---> Running in a3be98df73be
---> d3832c5b38c1
Removing intermediate container a3be98df73be
Step 3 : ENV ORACLE_HOME /u01/oracle USER_MEM_ARGS "-Djava.security.egd=file:/dev/./urandom" PATH $PATH:/usr/java/default/bin:/u01/oracle/oracle_common/common/bin
---> Running in fb0773b87de2
---> 49ebdff9c0f2
Removing intermediate container fb0773b87de2
Step 4 : RUN mkdir -p /u01 && chmod a+xr /u01 && useradd -b /u01 -d /u01/oracle -m -s /bin/bash oracle && chown oracle:oracle -R /u01
---> Running in cb84a302230a
---> 81a0795cb544
Removing intermediate container cb84a302230a
Step 5 : ENV FMW_PKG fmw_12.1.3.0.0_wls.jar
---> Running in ba7ab1312206
---> ddb95b086113
Removing intermediate container ba7ab1312206
Step 6 : COPY $FMW_PKG install.file oraInst.loc /u01/
---> 95099fd96c30
Removing intermediate container 848ed94e0775
Step 7 : USER oracle
---> Running in e8a160c7caa1
---> 6e6dfc3527ee
Removing intermediate container e8a160c7caa1
Step 8 : RUN $JAVA_HOME/bin/java -jar /u01/$FMW_PKG -ignoreSysPrereqs -novalidation -silent -responseFile /u01/install.file -invPtrLoc /u01/oraInst.loc -jreLoc $JAVA_HOME ORACLE_HOME=$ORACLE_HOME INSTALL_TYPE="WebLogic Server" && rm /u01/$FMW_PKG /u01/oraInst.loc /u01/install.file
---> Running in 7e844f2f164b
Launcher log file is /tmp/OraInstall2017-05-08_01-43-40AM/launcher2017-05-08_01-43-40AM.log.
Extracting files.............
Starting Oracle Universal InstallerChecking if CPU speed is above 300 MHz. Actual 2494.162 MHz Passed
Checking swap space: must be greater than 512 MB. Actual 839676 MB Passed
Checking if this platform requires a 64-bit JVM. Actual 64 Passed (64-bit not required)
Checking temp space: must be greater than 300 MB. Actual 8146 MB Passed
Preparing to launch the Oracle Universal Installer from /tmp/OraInstall2017-05-08_01-43-40AM
Java HotSpot(TM) 64-Bit Server VM warning: ignoring option MaxPermSize=512m; support was removed in 8.0
Log: /tmp/OraInstall2017-05-08_01-43-40AM/install2017-05-08_01-43-40AM.log
Setting ORACLE_HOME to /u01/oracle
Setting INSTALL_TYPE to WebLogic Server
Copyright (c) 1996, 2014, Oracle and/or its affiliates. All rights reserved.
Reading response file..
Validations are disabled for this session.
Verifying data......
Copying Files...
You can find the log of this install session at:
/tmp/OraInstall2017-05-08_01-43-40AM/install2017-05-08_01-43-40AM.log
-----------20%----------40%----------60%----------80%--------100%The installation of Oracle Fusion Middleware 12c WebLogic Server and Coherence 12.1.3.0.0 completed successfully.
Logs successfully copied to /u01/oracle/.inventory/logs.
---> 7588fb8b1ea1
Removing intermediate container 7e844f2f164b
Step 9 : WORKDIR $ORACLE_HOME
---> Running in 2653c76fc994
---> fc3cfaae5e57
Removing intermediate container 2653c76fc994
Step 10 : CMD bash
---> Running in f4b21a3fb17b
---> 5d5e3db57694
Removing intermediate container f4b21a3fb17b
Successfully built 5d5e3db57694 WebLogic Docker Image for 'generic' version 12.1.3 is ready to be extended:

--> oracle/weblogic:12.1.3-generic Build completed in 210 seconds. 

如果sudo出错,解决办法:
以root用户修改/etc/sudoer 文件属性为root可修改,并在root ALL 行下添加 weblogic ALL(类似root行)
# chmod u+w sudoers 
# vi sudoers 
添加 weblogic    ALL=(ALL)    ALL





通过docker images查看本地的镜像



建立一个空域的weblogic container

进入sample目录下1213-domain目录,修改脚本,让上面的域基于generic来构件,然后运行

docker build -t 1213-domain . 或者是
sudo docker build -t 1213-domain --build-arg ADMIN_PASSWORD=welcome1 .



 

 

[weblogic@k8s-node-1 1213-domain]$ sudo docker build -t 1213-domain --build-arg ADMIN_PASSWORD=welcome1 .
Sending build context to Docker daemon 27.14 kB
Step 1 : FROM oracle/weblogic:12.1.3-generic
---> 5d5e3db57694
Step 2 : MAINTAINER Bruno Borges <bruno.borges@oracle.com>
---> Using cache
---> 0870893aeb94
Step 3 : ARG ADMIN_PASSWORD
---> Using cache
---> f96881560dd6
Step 4 : ARG PRODUCTION_MODE
---> Using cache
---> 71a8ea620d2f
Step 5 : ENV DOMAIN_NAME "base_domain" DOMAIN_HOME "/u01/oracle/user_projects/domains/base_domain" ADMIN_PORT "7001" ADMIN_HOST "wlsadmin" NM_PORT "5556" MS_PORT "7002" PRODUCTION_MODE "${PRODUCTION_MODE:-prod}" CONFIG_JVM_ARGS "-Dweblogic.security.SSL.ignoreHostnameVerification=true" PATH $PATH:/u01/oracle/oracle_common/common/bin:/u01/oracle/wlserver/common/bin:/u01/oracle/user_projects/domains/base_domain/bin:/u01/oracle
---> Using cache
---> a1a3b1491eb2
Step 6 : USER oracle
---> Using cache
---> 07a40e8318fb
Step 7 : COPY container-scripts/* /u01/oracle/
---> Using cache
---> 3fa0db902628
Step 8 : WORKDIR /u01/oracle
---> Using cache
---> 5456eb401629
Step 9 : RUN /u01/oracle/wlst /u01/oracle/create-wls-domain.py && mkdir -p /u01/oracle/user_projects/domains/base_domain/servers/AdminServer/security && echo "username=weblogic" > /u01/oracle/user_projects/domains/base_domain/servers/AdminServer/security/boot.properties && echo "password=$ADMIN_PASSWORD" >> /u01/oracle/user_projects/domains/base_domain/servers/AdminServer/security/boot.properties && echo ". /u01/oracle/user_projects/domains/base_domain/bin/setDomainEnv.sh" >> /u01/oracle/.bashrc && echo "export PATH=$PATH:/u01/oracle/wlserver/common/bin:/u01/oracle/user_projects/domains/base_domain/bin" >> /u01/oracle/.bashrc && cp /u01/oracle/commEnv.sh /u01/oracle/wlserver/common/bin/commEnv.sh && rm /u01/oracle/create-wls-domain.py /u01/oracle/jaxrs2-template.jar
---> Running in 19bd5397ef26

Initializing WebLogic Scripting Tool (WLST) ...

Welcome to WebLogic Server Administration Scripting Shell

Type help() for help on available commands

domain_name : [base_domain]
admin_port : [7001]
cluster_name: [DockerCluster]
domain_path : [/u01/oracle/user_projects/domains/base_domain]
production_mode : [prod]


Exiting WebLogic Scripting Tool.

---> d35626c7b868
Removing intermediate container 19bd5397ef26
Step 10 : EXPOSE $NM_PORT $ADMIN_PORT $MS_PORT
---> Running in 12bb8b3bd00f
---> c9f2a9df2fc6
Removing intermediate container 12bb8b3bd00f
Step 11 : WORKDIR $DOMAIN_HOME
---> Running in 10935b7fde01
---> 6146bdb88ea7
Removing intermediate container 10935b7fde01
Step 12 : CMD startWebLogic.sh
---> Running in e1895ffb93af
---> 075e44ddb763
Removing intermediate container e1895ffb93af
Successfully built 075e44ddb763

 

运行容器

docker run -d 1213-domain

因为当前启动命令为startWebLogic.sh,所以通过logs可以看到weblogic启动日志.

此外还有另外两种启动方式:

docker run -d --name wlsadmin --hostname wlsadmin -p 8001:8001 1213-domain

docker run -d -p 8001:8001 --name=wlsadmin 1213-domain startWebLogic.sh

 

docker logs $container id

docker inspect <container_id> | grep "IPAddress"

 

然后运行http://172.17.0.1:8001/console,进入weblogic管理控制台(weblogic/welcome1)

 

 

修改容器,部署一个helloworld的应用,修改完commit

 

sudo docker commit -m "Added HelloWorld Application" -a "Eric Nie" 1a4f7376802f823ce71015a232b85810db17eec38ed54670d1ca06fb4f0e750e 1213-helloworld:v1
posted @ 2016-02-13 19:52  ericnie  阅读(6500)  评论(4编辑  收藏  举报