基本場景和問題描述
目前的應(yīng)用場景是學(xué)校課題組希望對(duì)外開放一個(gè)即時(shí)計(jì)算、渲染科學(xué)數(shù)據(jù)的平臺(tái),因?yàn)樾枰^多計(jì)算資源選在校內(nèi)服務(wù)器上部署一個(gè)Django前后端網(wǎng)頁,但是管理非常嚴(yán)格,不能給出sudo權(quán)限,包括對(duì)docker的調(diào)用。為解決這個(gè)問題探索了了rootless的docker部署方案。
Rootless Docker安裝和配置
教程見官方文檔和中文文檔,已經(jīng)較為詳細(xì)。因?yàn)橥耆珱]有sudo權(quán)限,我們選用不使用軟件包,直接運(yùn)行安裝腳本的方法。需要注意的是,中文網(wǎng)站上直接照搬了原curl -fsSL https://get.docker.com/rootless | sh的命令,訪問有問題,腳本內(nèi)容中還涉及到從download.docker.com下載,同樣無法訪問,可以先考慮在本地下載下載下來,將download.docker.com替換為mirrors.tuna.tsinghua.edu.cn/docker-ce或其他源,再運(yùn)行腳本。在我的服務(wù)器上,還提示缺少iptables相關(guān)的依賴:
# Missing system requirements. Please run following commands to
# install the requirements and run this installer again.
# Alternatively iptables checks can be disabled with SKIP_IPTABLES=1
也沒有權(quán)限安裝,于是根據(jù)提示運(yùn)行:
SKIP_IPTABLES=1 sh rootless
這會(huì)把docker相關(guān)的一系列可執(zhí)行文件安裝到$HOME/bin下,如果$HOME/bin還不在$PATH中則將其加入。但是還缺少了常用的``docker-compose`,可從GitHub上下載:
mkdir -p ~/.docker/cli-plugins/
curl -SL https://githubfast.com/docker/compose/releases/download/v2.2.3/docker-compose-linux-x86_64 -o ~/.docker/cli-plugins/docker-compose #使用鏡像
chmod +x ~/.docker/cli-plugins/docker-compose
注意到與一般模式下的docker不同,暫未找到rootless模式下的docker訪問宿主機(jī)網(wǎng)絡(luò)的方式,不能執(zhí)行直接從公共源下載類的操作。因此在內(nèi)部進(jìn)行項(xiàng)目的構(gòu)建和部署時(shí),依賴的軟件包需要從宿主機(jī)復(fù)制,如對(duì)于Python依賴,可以使用類似的方法修改原來的配置:
# 命令行運(yùn)行
pip download -d /app/dependencies -r requirements.txt
# dockerfile
WORKDIR /app
COPY requirements.txt /app/
COPY dependencies /app/dependencies/
RUN pip install --no-cache-dir --no-index --find-links=/app/dependencies -r requirements.txt
這樣根據(jù)docker-compose.yml中定義的轉(zhuǎn)發(fā)規(guī)則,就可以在宿主機(jī)上正常得到服務(wù)的端口。
本文由博客一文多發(fā)平臺(tái) OpenWrite 發(fā)布!