2017-04-21 296 views
0

我通過在容器中安裝應用程序(應該是root用戶進行安裝)來創建Docker鏡像。無法構建docker鏡像,「必須是root用戶」

# cat Dockerfile 
FROM ubuntu:16.04 
COPY $pwd/intel_virtual_gateway_console64_1_9_0.tar /root/ 
COPY $pwd/login.exp /root/ 
WORKDIR /root/ 
RUN tar -xvf intel_virtual_gateway_console64_1_9_0.tar 
RUN apt-get update && apt-get install -y expect \ 
         expect-dev \ 
         libxml2-utils 
RUN whoami 
RUN expect login.exp 

的搬運工映像構建過程:

[email protected]:~/RAGHU/krishna# docker build -t release:4.0 . 
Sending build context to Docker daemon 633.5MB 
Step 1/8 : FROM ubuntu:16.04 
---> 6a2f32de169d 
Step 2/8 : COPY $pwd/intel_virtual_gateway_console64_1_9_0.tar /root/ 
---> Using cache 
---> 36e9ea407082 
Step 3/8 : COPY $pwd/login.exp /root/ 
---> Using cache 
---> 0fad538973d4 
Step 4/8 : WORKDIR /root/ 
---> Using cache 
---> f5d7f36bc37f 
Step 5/8 : RUN tar -xvf intel_virtual_gateway_console64_1_9_0.tar 
---> Using cache 
---> 6cab428f1bc2 
Step 6/8 : RUN apt-get update && apt-get install -y expect      expect-dev      libxml2-utils 
---> Using cache 
---> 5bb1ee67332f 

要確認容器運行爲root用戶:

Step 7/8 : RUN whoami 
---> Running in 112b87d77a08 
root 
---> 0c7eb38cc06b 
Removing intermediate container 112b87d77a08 
Step 8/8 : RUN expect login.exp 
---> Running in 5f186baf2f8d 
spawn ./virtualgatewayconsole_package/virtual_gateway_console_intel64 
Install Error 
-------------------------------------------------------------------------------- 
To install the application, you must be a root user. 
-------------------------------------------------------------------------------- 
Type any key to exit: ^C 

無法找出爲什麼應用程序安裝失敗,即使它以root用戶身份運行。

編輯:添加login.exp腳本:此腳本非常基本,可以完成我的功能。

#cat login.exp 
#!/usr/bin/expect -f 

if 0 { 
    *************************READ THIS BEFORE START********************* 
    User password must consist of at least 3 of the following categories: 
    uppercase, lowercase, numeric, and non-alphanumeric. In case of violation 
    of this rule the Installation will fail! 
    ******************************************************************** 
    } 
set passwd "[email protected]" 
set username "raghu" 

spawn ./virtualgatewayconsole_package/virtual_gateway_console_intel64 
expect "Press Enter key to continue or q to quit:" 
send "\n" 

expect "Press ENTER for more, or q when done" 
send "q" 

sleep 5 
#expect "conditions of this license agreement?" 
expect "*(accept/decline): " 
send "accept\n" 

#Product installation 
expect "*Please type a selection \[1\]:" 
send "\n" 

expect "*Please type a selection (Press Enter to next):" 
send "\n" 

sleep 2 
#Configure TLS settings 
expect "*Enter TLS keystore password (only numbers, letters and [email protected]#$%^*()_+{}|.:?=-):" 
send $passwd 
send "\n" 

expect "*Retype TLS keystore password:" 
send $passwd 
send "\n" 

sleep 2 
expect "Please type a selection (Press Enter to next):" 
send "\n" 

#Configure host 
expect "Please type a selection (Press Enter to next):" 
send "\n" 

expect "Please type a selection (Press Enter to next):" 
send "\n" 

#Configure user for logging on the management console 
expect "Please type a selection (Press Enter to next):" 
send "\n" 

sleep 2 
expect "Enter user password (only numbers, letters, spaces and [email protected]#$%^*()_+{}|.:?=-):" 
send $passwd 
send "\n" 

expect "Retype user password:" 
send $passwd 
send "\n" 

expect "Please type a selection (Press Enter to next):" 
send "\n" 

sleep 2 
#Configure PostgreSQL service 
expect "Please type a selection (Press Enter to next):" 
send "\n" 

expect "Enter PostgreSQL user password (only numbers, letters and [email protected]#$%^*()_+{}|.:?=-):" 
send $passwd 
send "\n" 

expect "Retype PostgreSQL user password:" 
send $passwd 
send "\n" 

expect "Please type a selection (Press Enter to next):" 
send "\n" 

sleep 60 
#Create Keystore 
expect "What is your first and last name?" 
send $username 
send "\n" 

expect "What is the name of your organizational unit?" 
send "radisys" 
send "\n" 

expect "What is the name of your organization?" 
send "radisys" 
send "\n" 

sleep 2 
expect "What is the name of your City or Locality?" 
send "banglore" 
send "\n" 

expect "What is the name of your State or Province?" 
send "karnataka" 
send "\n" 

expect "What is the two-letter country code for this unit?" 
send "IND" 
send "\n" 

sleep 2 
expect "Is CN=raghu, OU=radisys, O=radisys, L=banglore, ST=karnataka, C=IND correct?" 
send "yes" 
send "\n" 

sleep 2 
expect "Please type a selection \[q\]:" 
send "q" 

expect eof 
+2

'login.exp'中有什麼? – jwodder

+0

期望通常監視模式的輸出以檢測它正在尋找的東西。沒有看到'login.exp',我猜想它正在尋找一個它認爲意味着「root用戶」的shell提示符模式,它沒有看到特定的模式。 –

回答

1

容器版本的根和你在主機上知道的根並不一定是相同的東西。最大的區別是,docker從root用戶中刪除了各種功能,以防止它們突破容器,因此用戶無法訪問物理硬件設備,他們可以直接在容器中安裝硬盤驅動器,或者調整cgroup設置來轉義命名空間。

從您運行的文件的名稱看來,您似乎正在嘗試安裝需要訪問硬件的KVM。我認爲這不是用於便攜和隔離硬件的容器的最佳使用案例,而這個應用程序很可能設計有硬件專用配置和訪問作爲關鍵要求。

雖然docker build不允許硬件訪問,但您可以使用docker run --privileged手動執行安裝,然後docker commit將該容器保存到映像。這通常是您想要構建圖像的最後一種方式,但在這種情況下,它可能是唯一的方法,假設它可能。

相關問題