1.docker建立鏡像并且發(fā)布到倉庫

本文說的是建立dockerapp的基本步聚,前提docker已經(jīng)安裝成功


1.The app itself(建立應(yīng)用)

建立一個文件夾,在文件夾下邊建立三個文件,如下所示:

$ls

Dockerfile ? ?app.py ? requirements.txt

三個文件的具體內(nèi)容如下:

Dockerfile

# Use an official Python runtime as a base image

FROM python:2.7-slim

# Set the working directory to /app

WORKDIR /app

# Copy the current directory contents into the container at /app

ADD . /app

# Install any needed packages specified in requirements.txt

RUN pip install -r requirements.txt

# Make port 80 available to the world outside this container

EXPOSE 80

# Define environment variable

ENV NAME World

# Run app.py when the container launches

CMD ["python", "app.py"]

requirements.txt

Flask

Redis

app.py


通過pip安裝requirements.txt中的依賴 redis flask

pip install -r requirements.txt?



?

2.Build the App

$lsDockerfileapp.pyrequirements.txt ?

#建立應(yīng)用

docker build -t friendlyhello . ? 建立名為friendlyhello的應(yīng)用

查看建立的應(yīng)用

$docker images

REPOSITORY? ? ? ? ? ? TAG? ? ? ? ? ? ? ? IMAGE ID

friendlyhello? ? ? ? latest? ? ? ? ? ? ? 326387cea398



3.Run the app ? #運行app

Run the app, mapping your machine’s port 4000 to the container’sEXPOSEd port 80 using-p:

docker run -p 4000:80 friendlyhello ? #在前臺運行

Now let’s run the app in the background, in detached mode:

docker run -d -p 4000:80 friendlyhello ?#后臺運行




4.查看docker運行的應(yīng)用

$docker ps


通過 http://localhost:4000訪問應(yīng)用.

5.#通過containet Id 來停止app

Now use docker stop to end the process, using the CONTAINER ID, like so:

docker stop e36ae6aaad8f

6.Share your image(分享鏡像)

一、If you don’t have a Docker account, sign up for one at?cloud.docker.com. Make note of your ? username.(如果沒有docker帳號注冊一個)

二、Log in your local machine.(輸入下邊命名登錄)

? docker login (根據(jù)提示輸入用戶名密碼)

三、發(fā)布景象:

給app打標記

docker tag friendlyhello username/repository:tag

friendlyhello #為app的名稱

username:你注冊的docker的名字

repository:你建立的docker鏡像的倉庫

tag:應(yīng)用打一個標記號,版本的變遷

Upload your tagged image:(上傳鏡像)

docker push username/repository:tag

上傳后可以在你的docker看到剛才上傳的應(yīng)用鏡像,這個是公開可用的

7.使用你放在docker 倉庫的鏡像

Once complete, the results of this upload are publicly available. From now on, you can use docker run and run your app on any machine with this command:

運行命令如下:

docker run -p 4000:80 username/repository:tag




最后編輯于
?著作權(quán)歸作者所有,轉(zhuǎn)載或內(nèi)容合作請聯(lián)系作者
平臺聲明:文章內(nèi)容(如有圖片或視頻亦包括在內(nèi))由作者上傳并發(fā)布,文章內(nèi)容僅代表作者本人觀點,簡書系信息發(fā)布平臺,僅提供信息存儲服務(wù)。

推薦閱讀更多精彩內(nèi)容