docker容器的構建

2022-06-30 06:24:09 字數 2025 閱讀 6730

構建容器的方法:

(1)命令docker  commit

執行容器的三個步驟:執行+修改+儲存映象

例子:拉取映象

docker pull centos

建立容器

docker run -itd e934aafc2206 /bin/bash

進入容器修改容器

docker exec -it e6e5f719f74c /bin/bash

yum -y install net-tools vim

將修改後的容器做成映象

docker commit e6e5f719f74c centos-with-vim/nettools:1.0

刪除修改後的容器

docker ps

docker rm -f e6e5f719f74c

docker ps

docker images

測試修改後的映象是不是你新增的東西

docker run -it centos-with-vim/nettools:1.0

(2)dockerfile構建檔案,

例子:vim dockerfile

from centos

run yum install net-tools -y

run yum install elinks -y

cmd ["/bin/bash"]

執行dockerfile檔案

docker build -t centos-nginx:test ./

注釋;centos-nginx:test 新映象名稱:標籤

(4)檢視映象執行過程,

docker history centos-with-vim/nettools:1.0

(5)映象的快取特性:

1.當映象裡執行過的層就會跳過,執行新新增的層以及往下的已經有的或者沒有的層.修改的時候

2.新增加的資料之只能往上層增加,才會有快取特性,不能往下層增加,否則快取特效就美譽了,也就會重寫這個檔案,如果不想要這個快取特性,則新增no-cache

vim testfile

this is wode coustom imags

:wqvim dockerfile

from centos

run yum install net-tools -y

copy testfile /

run yum install elinks -y

cmd ["/bin/bash"]

(6)容器的除錯方法:

vim dockerfile

from busybox

run yum install net-tools -y

copy testfile /

run yum install elinks -y

cmd ["/bin/bash"]

docker build -t haha:test ./

docker run -it 進入報錯的上乙個容器執行,然後並執行報錯的命令,這是排除錯誤思路

(7)一次性容器執行

docker run  -it e934aafc2206

新增: 

docker檔案的引數詳解

vim dockerfile

from: 基礎映象

maintainer:作者資訊

copy:src(host) dest(container)

add:拷貝到container同時解壓

env:變數

expose:指定容器中的程序監聽某個埠

volume:目錄檔案對映到容器

workdir:為後面所有的命令提供目錄

run:容器執行的命令

cmd:容器啟動時執行的命令(可被代替)

entrypoint:容器啟動時的執行命令,只能有乙個,不會被替換。

Docker構建web容器

一 docker構建方式 1 非微服務專案部署方式 docker run name web應用名 p 8280 8080 v web應用名 web應用名 v usr local logs tomcat web應用名 usr local soft tomcat logs d centos7 tomca...

Docker小記 從容器構建映象

這條命令會啟動乙個執行bash shell的新容器。基於這個shell,你就能夠輸入命令來自定義你的容器了 docker run it name image dev ubuntu latest bin bashdocker commit old container name new containe...

在Docker上構建mysql容器

root holly holly docker images 如果沒有只會看到如下結構 repository tag image id created size 語法為 docker pull 軟體名稱 版本號 root holly holly docker pull mysql 5.6 root ...