1. 程式人生 > 其它 >docker初體驗:docker 自己定製映象

docker初體驗:docker 自己定製映象

Docker 是一個開源的應用容器引擎,基於 Go 語言 並遵從 Apache2.0 協議開源。Docker 可以讓開發者打包他們的應用以及依賴包到一個輕量級、可移植的容器中,然後釋出到任何流行的Linux機器上,也可以實現虛擬化。接下來為大家演示一下docker部署wordpress部落格系統。
環境

centos7

安裝docker 移除舊版本docker
[root@chaols ~]#  sudo yum remove docker \
>                   docker-client \
>                   docker-client-latest \
>                   docker-common \
>                   docker-latest \
>                   docker-latest-logrotate \
>                   docker-logrotate \
>                   docker-engine
安裝yum-utils包並設定穩定儲存庫
[root@chaols ~]# yum install -y yum-utils
安裝docker
[root@chaols ~]# yum install docker-ce docker-ce-cli containerd.io
啟動docker
[root@chaols ~]# systemctl start docker
檢視docker映象

剛剛安裝docker是沒有映象的

[root@chaols ~]# docker images
REPOSITORY   TAG       IMAGE ID   CREATED   SIZE
下載centos映象
[root@chaols ~]# docker pull centos

預設centos映象沒有ifconfig

自定義dockerfile檔案
FROM centos
ENV MYPATH /usr/local
WORKDIR $MYPATH
RUN yum install -y net-tools
RUN yum install -y vim
EXPOSE 80
CMD echo $MYPATH
CMD echo "-----end-----"
CMD /bin/bash"
開始製作
docker build -f ./dockerfile_chao_centos -t chao.centos:0.1 .
建立虛擬機器
root@chaols ~]# docker run -it --name test chao.centos:0.1 /bin/bash
驗證ifconfig
[root@f5be14eebc1e local]# ifconfig
eth0: flags=4163<up,broadcast,running,multicast>  mtu 1500
        inet 172.17.0.2  netmask 255.255.0.0  broadcast 172.17.255.255
        ether 02:42:ac:11:00:02  txqueuelen 0  (Ethernet)
        RX packets 6  bytes 516 (516.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

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

本文原創地址:https://www.linuxprobe.com/docker-docker-images.html