国产 无码 综合区,色欲AV无码国产永久播放,无码天堂亚洲国产AV,国产日韩欧美女同一区二区

【編寫DockerFile構(gòu)建自己的容器】

這篇具有很好參考價值的文章主要介紹了【編寫DockerFile構(gòu)建自己的容器】。希望對大家有所幫助。如果存在錯誤或未考慮完全的地方,請大家不吝賜教,您也可以點擊"舉報違法"按鈕提交疑問。

實戰(zhàn):構(gòu)建自己的CentOS

一、創(chuàng)建自己的CentOS

(1)、編寫自己的配置文件

[root@localhost home]# mkdir dockerfile-1
[root@localhost home]# cd dockerfile-1
[root@localhost dockerfile-1]# vi docker-centos

#需要構(gòu)建的鏡像
FROM centos:7  

#如果不指定版本那么默認會生成Centos8的鏡像,
#而我們現(xiàn)在用的是Centos7,安裝命令的時候yum倉庫會和Centos8的不兼容,從而導致保存無法完成鏡像的創(chuàng)建和命令的安裝

MAINTAINER grj<3374864596@qq.com>  ==>鏡像作者的信息

WORKDIR /usr/local ==>工作目錄

#需要安裝的命令
RUN yum -y install vim
RUN yum -y install net-tools

#映射80端口
EXPOSE 80

#命令提示符輸出
CMD echo "---End---"
CMD /bin/bash

(2)、生成目標鏡像

[root@localhost dockerfile1]# docker build -f /home/dockerfile1/docker-centos -t docker-centos:1.0 .
Sending build context to Docker daemon  2.048kB
Step 1/8 : FROM centos
 ---> 5d0da3dc9764
Step 2/8 : MAINTAINER grj<3374864596@qq.com>

... ...

Successfully built 3f478b749d2e ==>當看到了這兩個Successfully則表示創(chuàng)建成功

Successfully tagged docker-centos:1.0 

docker build -f /home/dockerfile1/docker-centos -t docker-centos:1.0 .

  • 命令: docker build -f 文件路徑 -t 鏡像名:【Tag】

(3)、測試運行

  • 系統(tǒng)的原生鏡像
[root@localhost dockerfile1]# docker run -it eeb6ee3f44bd /bin/bash 
[root@08a6a834848a /]# 
[root@08a6a834848a /]# pwd  ==>默認工作目錄為/
/
[root@08a6a834848a /]# 
[root@08a6a834848a /]# ifconfig  ==>一些基礎的命令無法使用
bash: ifconfig: command not found
[root@08a6a834848a /]# 
[root@08a6a834848a /]# vim 1.txt  ==>一些基礎的命令無法使用
bash: vim: command not found
  • 我們制作的鏡像
[root@localhost dockerfile1]# docker run -it 3f478b749d2e /bin/bash
[root@515ac8e584d0 local]# pwd  ==>默認工作目錄為/usr/local
/usr/local
[root@515ac8e584d0 local]# ifconfig ==>命令可以使用
eth0: flags=4163<UP,BROADCAST,RUNNING,MULTICAST>  mtu 1500
        inet 172.17.0.3  netmask 255.255.0.0  broadcast 172.17.255.255
        ether 02:42:ac:11:00:03  txqueuelen 0  (Ethernet)
        RX packets 14  bytes 1218 (1.1 KiB)
        RX errors 0  dropped 0  overruns 0  frame 0
        TX packets 6  bytes 439 (439.0 B)
        TX errors 0  dropped 0 overruns 0  carrier 0  collisions 0

lo: flags=73<UP,LOOPBACK,RUNNING>  mtu 65536
        inet 127.0.0.1  netmask 255.0.0.0
        loop  txqueuelen 1000  (Local Loopback)
        RX packets 0  bytes 0 (0.0 B)
        RX errors 0  dropped 0  overruns 0  frame 0
        TX packets 0  bytes 0 (0.0 B)
        TX errors 0  dropped 0 overruns 0  carrier 0  collisions 0

[root@515ac8e584d0 local]# vim 1.txt ==>命令可以使用

(4)、查看docker的構(gòu)建流程

[root@localhost ~]# docker history eeb6ee3f44bd
IMAGE          CREATED        CREATED BY                                      SIZE      COMMENT
eeb6ee3f44bd   7 months ago   /bin/sh -c #(nop)  CMD ["/bin/bash"]            0B        
<missing>      7 months ago   /bin/sh -c #(nop)  LABEL org.label-schema.sc…   0B        
<missing>      7 months ago   /bin/sh -c #(nop) ADD file:b3ebbe8bd304723d4…   204MB 

docker history eeb6ee3f44bd

二、CMD和ENTRYPOINT

  • CMD
CMD         #指定這個容器啟動的時候需要運行的命令,只有最后一個會生效,可替代
ENTRYPOINT  #指定這個容器啟動的時候要運行的命令??梢宰芳用?。

#編寫dockerfile文件
[root@localhost dockerfile1]# vi docker-centos-1 
FROM centos:7
CMD ["ls","-a"]

#構(gòu)建鏡像
[root@localhost dockerfile1]# docker build -f docker-centos-1 -t cmdtest .
Sending build context to Docker daemon  3.072kB
Step 1/2 : FROM centos:7
 ---> eeb6ee3f44bd
Step 2/2 : CMD ["ls","-a"]
 ---> Running in 1770ec84cf7d
Removing intermediate container 1770ec84cf7d
 ---> e8ee368cfd82
Successfully built e8ee368cfd82
Successfully tagged cmdtest:latest

#run運行,發(fā)現(xiàn)我們啟動鏡像的時候“l(fā)s -a”命令運行生效
[root@localhost dockerfile1]# docker run e8ee368cfd82
.
..
.dockerenv
anaconda-post.log

... ...

usr
var

#追加一個命令“-l”,發(fā)現(xiàn)報錯
[root@localhost dockerfile1]# docker run e8ee368cfd82 -l
docker: Error response from daemon: failed to create shim: OCI runtime create failed: container_linux.go:380: starting container process caused: exec: "-l": executable file not found in $PATH: unknown.
ERRO[0001] error waiting for container: context canceled 

#需要我們在后面操作一個完整的命令才能執(zhí)行
[root@localhost dockerfile1]# docker run e8ee368cfd82 ls -al
total 12

... ...
drwxrwxrwt.   7 root root   132 Nov 13  2020 tmp
drwxr-xr-x.  13 root root   155 Nov 13  2020 usr
drwxr-xr-x.  18 root root   238 Nov 13  2020 var
  • ENTRYPOINT
[root@localhost dockerfile1]# vi docker-centos-ENTRYPOINT
FROM centos
ENTRYPOINT ["ls","-a"]

[root@localhost dockerfile1]# docker build -f docker-centos-ENTRYPOINT -t entrypoint-tesy .
Sending build context to Docker daemon  4.096kB
Step 1/2 : FROM centos
... ...

#我們可以發(fā)現(xiàn)在ENTRYPOINT環(huán)境下命令是可以直接追加執(zhí)行不需要覆蓋
[root@localhost dockerfile1]# docker run 4acf07817552 -l
total 0
... ...
drwxr-xr-x.  12 root root 144 Sep 15  2021 usr
drwxr-xr-x.  20 root root 262 Sep 15  2021 var


Tips:

(1)、

  • ocker:IPv4 forwarding is disabled. Networking will not work.
    進入容器發(fā)現(xiàn)ipv4被禁用,容器內(nèi)部無法上網(wǎng)

解決方法:

#修改配置文件
[root@localhost ~]# vi /etc/sysctl.conf
net.ipv4.ip_forward=1

#驗證是否成功
[root@localhost ~]# sysctl net.ipv4.ip_forward
net.ipv4.ip_forward = 1

#重啟容器和網(wǎng)絡
[root@localhost ~]# systemctl restart network
[root@localhost ~]# systemctl restart docker

(2)、

  • Error: Failed to download metadata for repo ‘a(chǎn)ppstream’: Cannot prepare internal mirrorlist: No URLs in mirrorlist

yum報錯,從而導致保存無法完成鏡像的創(chuàng)建和命令的安裝

[root@localhost dockerfile1]# docker build -f docker-centos -t docker-centos:1.0 .
Sending build context to Docker daemon  4.096kB
Step 1/8 : FROM centos
 ---> 5d0da3dc9764
Step 2/8 : MAINTAINER grj<3374864596@qq.com>
 ---> Running in f87ee9c348b4
Removing intermediate container f87ee9c348b4
 ---> 31d964a88c41
Step 3/8 : WORKDIR /usr/local
 ---> Running in 3f54f1494fe6
Removing intermediate container 3f54f1494fe6
 ---> 4a89bd58e3f1
Step 4/8 : RUN yum -y install vim
 ---> Running in 041958a9f9c0
CentOS Linux 8 - AppStream                       71  B/s |  38  B     00:00    
Error: Failed to download metadata for repo 'appstream': Cannot prepare internal mirrorlist: No URLs in mirrorlist
The command '/bin/sh -c yum -y install vim' returned a non-zero code: 1

解決方法:

修改dockerfile文件,指定一個centos版本,如果不指定dockerhub默認按照最新的centos8,但是因為系統(tǒng)版本是centos7和centos8yum倉庫不兼容導致鏡像無法創(chuàng)建,命令無法安裝。

[root@localhost dockerfile1]# vi docker-centos

FROM centos:7
MAINTAINER grj<3374864596@qq.com>

WORKDIR /usr/local

RUN yum -y install vim
RUN yum -y install net-tools

EXPOSE 80
CMD echo "---End---"
CMD /bin/bash

三、Docker流程

dockerfile創(chuàng)建容器,Docker,docker,linux,運維,容器,云計算

dockerfile創(chuàng)建images容器鏡像,run運行容器,執(zhí)行操作commit打包鏡像保存到本地。push提交到dockerhub倉庫,或者也可以pull從dockerhub倉庫下載到本地

dockerfile創(chuàng)建容器,Docker,docker,linux,運維,容器,云計算文章來源地址http://www.zghlxwxcb.cn/news/detail-561063.html

到了這里,關(guān)于【編寫DockerFile構(gòu)建自己的容器】的文章就介紹完了。如果您還想了解更多內(nèi)容,請在右上角搜索TOY模板網(wǎng)以前的文章或繼續(xù)瀏覽下面的相關(guān)文章,希望大家以后多多支持TOY模板網(wǎng)!

本文來自互聯(lián)網(wǎng)用戶投稿,該文觀點僅代表作者本人,不代表本站立場。本站僅提供信息存儲空間服務,不擁有所有權(quán),不承擔相關(guān)法律責任。如若轉(zhuǎn)載,請注明出處: 如若內(nèi)容造成侵權(quán)/違法違規(guī)/事實不符,請點擊違法舉報進行投訴反饋,一經(jīng)查實,立即刪除!

領支付寶紅包贊助服務器費用

相關(guān)文章

  • Docker進階:容器數(shù)據(jù)卷與Dockerfile構(gòu)建鏡像(發(fā)布)

    Docker進階:容器數(shù)據(jù)卷與Dockerfile構(gòu)建鏡像(發(fā)布)

    ??The Begin??點點關(guān)注,收藏不迷路?? 1、完成數(shù)據(jù)持久化和共享數(shù)據(jù),docker容器中的數(shù)據(jù),同步到本地。 2、重要數(shù)據(jù)back_up 特點: 實時生效、數(shù)據(jù)卷可在容器之間共享和重用數(shù)據(jù)、數(shù)據(jù)卷中的更改不會包含在鏡像更新中、數(shù)據(jù)卷的生命周期會一直延續(xù)到?jīng)]有容器使用它為止

    2024年02月09日
    瀏覽(27)
  • Docker基礎入門:容器數(shù)據(jù)卷與Dockerfile構(gòu)建鏡像(發(fā)布)

    Docker基礎入門:容器數(shù)據(jù)卷與Dockerfile構(gòu)建鏡像(發(fā)布)

    ??The Begin??點點關(guān)注,收藏不迷路?? 1、完成數(shù)據(jù)持久化和共享數(shù)據(jù),docker容器中的數(shù)據(jù),同步到本地。 2、重要數(shù)據(jù)back_up 特點: 實時生效、數(shù)據(jù)卷可在容器之間共享和重用數(shù)據(jù)、數(shù)據(jù)卷中的更改不會包含在鏡像更新中、數(shù)據(jù)卷的生命周期會一直延續(xù)到?jīng)]有容器使用它為止

    2024年02月10日
    瀏覽(21)
  • Docker容器:docker數(shù)據(jù)管理、鏡像的創(chuàng)建及dockerfile案例

    Docker容器:docker數(shù)據(jù)管理、鏡像的創(chuàng)建及dockerfile案例

    因為數(shù)據(jù)寫入后如果停止了容器,再開啟數(shù)據(jù)就會消失,使用數(shù)據(jù)管理的數(shù)據(jù)卷掛載,實現(xiàn)了數(shù)據(jù)的持久化,重啟數(shù)據(jù)還會存在;還有一種方式,容器之間共享文件即相當于有個備份,也會解決停止容器后數(shù)據(jù)消失的問題。 管理 Docker 容器中數(shù)據(jù)主要有兩種方式:數(shù)據(jù)卷(

    2024年02月12日
    瀏覽(27)
  • Docker容器與虛擬化技術(shù):Docker鏡像創(chuàng)建、Dockerfile實例

    Docker容器與虛擬化技術(shù):Docker鏡像創(chuàng)建、Dockerfile實例

    目錄 一、理論 1.Docker鏡像的創(chuàng)建方法 2.Docker鏡像結(jié)構(gòu)的分層 3.Dockerfile 案例 4.構(gòu)建Systemctl鏡像(基于SSH鏡像) 5.構(gòu)建Tomcat 鏡像 6.構(gòu)建Mysql鏡像 二、實驗 1.Docker鏡像的創(chuàng)建 2.?Dockerfile 案例 3.構(gòu)建Systemctl鏡像(基于SSH鏡像) 三、問題 1.nginx網(wǎng)頁打不開 ?2.Apache容器啟動一直為Ex

    2024年02月12日
    瀏覽(94)
  • docker容器:docker鏡像的三種創(chuàng)建方法及dockerfile案例

    docker容器:docker鏡像的三種創(chuàng)建方法及dockerfile案例

    目錄 一、基于現(xiàn)有鏡像創(chuàng)建 1、創(chuàng)建啟動鏡像 2、生成新鏡像 二、基于本地模板創(chuàng)建? 1、OPENVZ 下載模板 2、導入容器生成鏡像 三、基于dockerfile創(chuàng)建? 1、dockerfile結(jié)構(gòu)及分層 2、聯(lián)合文件系統(tǒng) 3、docker鏡像加載原理 4、dockerfile操作常用的指令 (1)FROM指令 (2)MAINTAINER 指令 (3)RUN指令

    2023年04月20日
    瀏覽(41)
  • 【云原生】Docker鏡像的創(chuàng)建
Dockerfile 多階段構(gòu)建原理和使用場景

    【云原生】Docker鏡像的創(chuàng)建 Dockerfile 多階段構(gòu)建原理和使用場景

    創(chuàng)建鏡像有三種方法,分別為【基于已有鏡像創(chuàng)建】、【基于本地模板創(chuàng)建】以及【基于Dockerfile創(chuàng)建】。 (1)首先啟動一個鏡像,在容器里做修改 ?docker run -it --name web centos:7 /bin/bash ? ? #啟動容器 ?? ?yum install -y epel-release ?#安裝epel源 ?yum install -y nginx ? ? ? ? #安裝ng

    2024年02月12日
    瀏覽(30)
  • 如何在 Linux 命令行下玩轉(zhuǎn) Docker——如何使用 Dockerfile 來構(gòu)建和運行容器鏡像

    作者:禪與計算機程序設計藝術(shù) Docker 是一款開源的容器化技術(shù),它利用 Linux 內(nèi)核的容器特性,將應用部署到獨立的進程環(huán)境中?;谌萜骷夹g(shù)可以極大地提高開發(fā)者和運維人員的效率,降低部署、測試和生產(chǎn)環(huán)節(jié)中的成本,有效地實現(xiàn)云計算資源的彈性伸縮。 本文主要介紹

    2024年02月07日
    瀏覽(106)
  • Docker在windows下使用教程,通過Dockerfile創(chuàng)建鏡像/容器,以YOLO系列為例

    Docker在windows下使用教程,通過Dockerfile創(chuàng)建鏡像/容器,以YOLO系列為例

    ?通過可視化界面將極大的降低學習難度。 ?1.1、Docker Desktop下載 ?下載地址:Docker Desktop: The #1 Containerization Tool for Developers | Docker 應當是這個界面,選擇下載即可 1.2、下載完成后需打開window自帶的虛擬機 ? ? ? 將Hyper-V勾選即打開,勾選后需重啟。? 1.3、下載WSL,由于是在

    2024年02月05日
    瀏覽(103)
  • windows部署python項目(以Flask為例)到docker,通過腳本一鍵生成dockerfile并構(gòu)建鏡像啟動容器

    windows部署python項目(以Flask為例)到docker,通過腳本一鍵生成dockerfile并構(gòu)建鏡像啟動容器

    這里使用 pipreqs 進行依賴庫的識別。使用 pipreqs 可以自動檢索到當前項目下的所有組件及其版本,并生成 requirements.txt 文件。相比直接用pip freeze 命令,避免將整個python環(huán)境的依賴包寫入。 在項目的當前目錄中執(zhí)行 pipreqs ./ --encoding=utf8 --force 這里使用的是一個基于flask項目,

    2023年04月08日
    瀏覽(35)
  • 使用Dockerfile構(gòu)建自定義jdk鏡像,在使用jdk鏡像創(chuàng)建一個容器來外部訪問(一步一步來哦~好簡單的呢)

    使用Dockerfile構(gòu)建自定義jdk鏡像,在使用jdk鏡像創(chuàng)建一個容器來外部訪問(一步一步來哦~好簡單的呢)

    文章主人公:帥哥BUG??? 文章路人: 路人???? 路人??? ??:什么是dockerfile? ??:Dockerfile 是一個文本格式的配置文件, 用戶可以使用 Dockerfile 來快速創(chuàng)建自定義的鏡像,另外,使 用Dockerfile去構(gòu)建鏡像好比使用pom去構(gòu)建maven項目一樣,有異曲同工之妙 ??:知道了知道了,

    2024年02月09日
    瀏覽(22)

覺得文章有用就打賞一下文章作者

支付寶掃一掃打賞

博客贊助

微信掃一掃打賞

請作者喝杯咖啡吧~博客贊助

支付寶掃一掃領取紅包,優(yōu)惠每天領

二維碼1

領取紅包

二維碼2

領紅包