Docker安裝websphere(四)


在Docker容器里安裝webshpere

 

<!--前提:已經安裝好了docker,能夠正常使用。-->

(1)docker安裝websphere(需要賬號和密碼登錄,不掛載數據卷)

  1.   獲取鏡像:  docker pull  ibmcom/websphere-traditional:8.5.5.12-profile   
    docker pull  #是將鏡像拉取下來的命令,后面跟的是鏡像名以及鏡像版本信息
    ibmcom/websphere-traditional #websphere的鏡像名
    8.5.5.12-profile #鏡像的版本,也就是websphere的版本

     

  2. 使用鏡像生成容器並且啟動容器: 

    docker run --name websphere \

           -h websphere \

           -e UPDATE_HOSTNAME=true \

           -p 9043:9043 \

           -p 9443:9443 \

           --restart=always \

           -d ibmcom/websphere-traditional:8.5.5.12-profile

    docker run   #啟動容器的命令,后面跟各種參數 + 容器鏡像信息
    --name websphere #指定啟動的容器名為 websphere
    -e UPDATE_HOSTNAME=true #訪問websphere的ip不是localhost時需要此參數
    -p 9043:9043 #指定訪問端口號
    -d ibmcom/websphere-traditional:8.5.5.12-profile #后台運行該鏡像生成的容器

     

  3. 查看生成登錄的密碼: docker exec websphere cat /tmp/PASSWORD
    docker exec   #進入容器內部,訪問容器
    websphere #指定的容器名
    cat /tmp/PASSWORD #輸出容器內 /tmp/PASSWORD 文件中的內容 ,這條命令輸出的內容就是用於登錄的密碼。

     

  4. 通過瀏覽器訪問websphere:    https://172.150.13.40:9043/ibm/console/login.do?action=secure           
    172.150.13.40    #當前虛擬機的ip地址(每個人的都不一樣)
    9043 #設定訪問websphere的端口號

     

  5. 前面的步驟沒出錯,會進入如下登錄頁面
     
              

     

  6. 登錄的賬號和密碼(登錄的賬號都是一樣的,都是 wsadmin)

    賬號 :    wsadmin
    密碼 : 1+aIMDow (就是前面使用 docker exec websphere cat /tmp/PASSWORD 命令輸出的內容,每個人的都不一樣)

     

     登錄成功后,進入websphere主頁面。

 

如果忘記了websphere的密碼,可以使用docker exec websphere cat /tmp/PASSWORD 命令來查看登錄該容器的密碼,賬號都統一為 wsadmin。 (websphere為容器名

如果容器啟動不正常,可以使用 docker logs -f websphere 命令來查看容器啟動的日志信息,確定錯誤原因。websphere為容器名)

注意:websphere啟動需要的時間會比較長,所以需要參考日志的輸出來判斷容器是否已經啟動,不能立馬訪問,立馬訪問是不會有結果的。

 

(2)docker安裝websphere(無需賬號和密碼登錄,並且掛載數據卷到linux主機,映射到容器使用)    

  1.   獲取鏡像:  docker pull  ibmcom/websphere-traditional:8.5.5.12-profile   
    docker pull  #是將鏡像拉取下來的命令,后面跟的是鏡像名以及鏡像版本信息
    ibmcom/websphere-traditional #websphere的鏡像名
    8.5.5.12-profile #鏡像的版本,也就是websphere的版本

     

  2. 使用鏡像生成容器並且啟動容器: 

    docker run --name websphere \

           -h websphere \

           -e UPDATE_HOSTNAME=true \

           -p 9043:9043 \

           -p 9443:9443 \

           --restart=always \

           -d ibmcom/websphere-traditional:8.5.5.12-profile

    docker run   #啟動容器的命令,后面跟各種參數 + 容器鏡像信息
    --name websphere   #指定啟動的容器名為 websphere
    -e UPDATE_HOSTNAME=true #訪問websphere的ip不是localhost時需要此參數
    -p 9043:9043 #指定訪問端口號
    -d ibmcom/websphere-traditional:8.5.5.12-profile #后台運行該鏡像生成的容器

 

 

    3.使用docker cp命令,將容器內的../DefaultCell01目錄復制到linux主機上,用於映射。

    docker cp 8890fds8765f:/opt/IBM/WebSphere/AppServer/profiles/AppSrv01/config/cells/DefaultCell01 /root/docker/websphere/data

    將websphere容器中的 DefaultCell01目錄復制到 linux主機 /root/docker/websphere/data目錄下。

    注意:這里對目錄權限是有限制的,要將f復制到 linux主機 /root/docker/websphere/data目錄下的DefaultCell01目錄的UID改為與容器中的DefaultCell01目錄權限UID相同。

    使用命令 :  ls -l    # 查看目錄所屬者

    使用命令: id 用戶名  #查看用戶的詳細信息,比如 uid  gid 等等

    3.1  先進入websphere容器,查看DefaultCell01目錄的所屬者的uid。命令如下:

      docker exec -it websphere bash       #進入容器

      cd  /opt/IBM/WebSphere/AppServer/profiles/AppSrv01/config/cells/DefaultCell01  #進入容器內的DefaultCell01目錄

      ls  -l    #查看DefaultCell01目錄下的所有文件的詳細信息,會得知所屬用戶為 was

      id was  #查看用戶was的詳細信息,會得知was的uid為1000

      exit #退出容器,回到linux頁面

    3.2  進入linux的DefaultCell01目錄下,更改用戶的uid為1000

      cd /root/docker/websphere/data   #進入接收復制內容DefaultCell01文件的上一層目錄

      chown -R 1000:1000 DefaultCell01  #使用遞歸將DefaultCell01文件夾下的所有文件以及子文件的所屬者的uid都更改為1000

      cd DefaultCell01    #再進入DefaultCell01目錄

      chown -R 1000:1000 nodes   #使用遞歸將nodes文件夾下的所有文件以及子文件的所屬者的uid都更改為1000

    

    4.停止啟動的websphere容器,使用如下命令:

    docker stop websphere

 

    5.刪除停止的websphere容器,使用如下命令:

    docker rm websphere

       

    6.再次啟動容器,這時候需要添加-v參數來映射數據卷

    docker run --name websphere-admin \

          -p 9043:9043 \

          -p 9443:9443 \

          -h websphere-admin \

      -e UPDATE_HOSTNAME=true \

          -v /root/docker/websphere/data/DefaultCell01:/opt/IBM/WebSphere/AppServer/profiles/AppSrv01/config/cells/DefaultCell01 \

          --restart=always \

          -d ibmcom/websphere-traditional:8.5.5.12-profile

 

    注: 使用數據卷掛載目錄時, -v  /本機上的目錄:/容器內容的目錄

    例如:  -v /root/docker/webpshere/data/DefaultCell01:/opt/IBM/WebSphere/DefaultCell01

    意思是將本機的 /root/docker/webpshere/DefaultCell01文件中的內容掛載到容器內/opt/IBM/WebSphere/DefaultCell01目錄下,如果指定的本機目錄為空,則容器內指定的目錄也會為空,所以需要向拷貝一份數據到本機指定被掛載的目錄下。

    也可以理解為將本機指定目錄下的內容映射到容器內,供容器使用。

 

    7.將linux主機上 /root/docker/webpshere/data/DefaultCell01目錄下的security.xml文件中的第二行,enabled的值設置為false.

    用戶訪問websphere時就不用再輸入密碼了。

    使用 docker restart websphere 命令 ,重新啟動websphere。

    直接使用鏈接:  https://172.150.12.32:9043/admin  ,隨便輸入一個用戶名便可以訪問。

 

不需要密碼訪問的第二種方式,可以在用戶使用賬戶和密碼登錄websphere以后,

選擇 Security  -->  Global Sercurity  將 Administrative security取消選中,然后再重啟websphere就可以了。

依舊使用 https://172.150.12.32:9043/admin 訪問。


免責聲明!

本站轉載的文章為個人學習借鑒使用,本站對版權不負任何法律責任。如果侵犯了您的隱私權益,請聯系本站郵箱yoyou2525@163.com刪除。



 
粵ICP備18138465號   © 2018-2025 CODEPRJ.COM