2017-04-10 55 views
1

我在docker上安裝了Ubuntu 14.04鏡像。該鏡像帶有Ubuntu官方軟件源碼。由於我在中國,無法連接到這些服務器,因此我必須編輯etc/apt/source.list用vi或vim替換軟件源。但是,Ubuntu映像不會與兩個編輯器中的任何一個一起提供。如果我嘗試 來安裝編輯器,那麼我必須更改軟件源。我怎麼解決這個問題?無法替換docker中的軟件源碼Ubuntu鏡像

+2

從基礎圖像創建派生圖像,並在該腳本中使用sed更改源代碼 –

+0

感謝您的回覆,但我不知道如何使用sed。我用dockerfile來解決這個問題。 –

回答

1

如下您可以創建一個派生泊塢窗圖像:

Dockerfile

FROM ubuntu:14.04 
COPY ./sources.list /etc/apt/ 

sources.list(我在中國使用這些之前,他們的工作很好,跟你喜歡的人替換)

# See http://help.ubuntu.com/community/UpgradeNotes for how to upgrade to                                
# newer versions of the distribution. 
deb http://cn.archive.ubuntu.com/ubuntu/ trusty main restricted 
deb-src http://cn.archive.ubuntu.com/ubuntu/ trusty main restricted 
## Major bug fix updates produced after the final release of the 
## distribution. 
deb http://cn.archive.ubuntu.com/ubuntu/ trusty-updates main restricted 
deb-src http://cn.archive.ubuntu.com/ubuntu/ trusty-updates main restricted 
## N.B. software from this repository is ENTIRELY UNSUPPORTED by the Ubuntu 
## team. Also, please note that software in universe WILL NOT receive any 
## review or updates from the Ubuntu security team. 
deb http://cn.archive.ubuntu.com/ubuntu/ trusty universe 
deb-src http://cn.archive.ubuntu.com/ubuntu/ trusty universe 
deb http://cn.archive.ubuntu.com/ubuntu/ trusty-updates universe 
deb-src http://cn.archive.ubuntu.com/ubuntu/ trusty-updates universe 
## N.B. software from this repository is ENTIRELY UNSUPPORTED by the Ubuntu 
## team, and may not be under a free licence. Please satisfy yourself as to 
## your rights to use the software. Also, please note that software in 
## multiverse WILL NOT receive any review or updates from the Ubuntu 
## security team. 
deb http://cn.archive.ubuntu.com/ubuntu/ trusty multiverse 
deb-src http://cn.archive.ubuntu.com/ubuntu/ trusty multiverse 
deb http://cn.archive.ubuntu.com/ubuntu/ trusty-updates multiverse 
deb-src http://cn.archive.ubuntu.com/ubuntu/ trusty-updates multiverse 
## N.B. software from this repository may not have been tested as 
## extensively as that contained in the main release, although it includes 
## newer versions of some applications which may provide useful features. 
## Also, please note that software in backports WILL NOT receive any review 
## or updates from the Ubuntu security team. 
deb http://cn.archive.ubuntu.com/ubuntu/ trusty-backports main restricted universe multiverse 
deb-src http://cn.archive.ubuntu.com/ubuntu/ trusty-backports main restricted universe multiverse 
deb http://security.ubuntu.com/ubuntu trusty-security main restricted 
deb-src http://security.ubuntu.com/ubuntu trusty-security main restricted 
deb http://security.ubuntu.com/ubuntu trusty-security universe 
deb-src http://security.ubuntu.com/ubuntu trusty-security universe 
deb http://security.ubuntu.com/ubuntu trusty-security multiverse 
deb-src http://security.ubuntu.com/ubuntu trusty-security multiverse 
## Uncomment the following two lines to add software from Canonical's 
## 'partner' repository. 
## This software is not part of Ubuntu, but is offered by Canonical and the 
## respective vendors as a service to Ubuntu users. 
# deb http://archive.canonical.com/ubuntu trusty partner 
# deb-src http://archive.canonical.com/ubuntu trusty partner 
## This software is not part of Ubuntu, but is offered by third-party 
## developers who want to ship their latest software. 
#deb http://extras.ubuntu.com/ubuntu trusty main 
#deb-src http://extras.ubuntu.com/ubuntu trusty main 

創建這些文件後,您可以通過運行來構建映像,例如:

docker build --tag ubuntu:14.04-cn 

並在您的項目中使用它,如果您需要將其上傳到碼頭集線器,則需要相應地更改名稱。

此外,我建議您直接在圖像中安裝所需的軟件,這樣您不必在每次啓動容器時都安裝依賴項,因爲無論如何您都在構建圖像。

+0

感謝您提供詳細的重播和有用的建議。我是初學者,所以我需要摸索很多東西。 –

+0

如果答案正確解決了您的問題,請將其標記爲正確,以便其他人可以在將來遵循同一個系統。如果沒有讓我知道,如果有什麼東西不能正常工作,我可以修改它。 – oirad

相關問題