Docker 學習製作第一個映象
阿新 • • 發佈:2018-12-26
mac 下安裝docker
安裝成功後執行docker daemon
在命令列執行 docker info 可以檢視當前docker 的狀態
此時docker中沒用正在執行的任務,Images : 2 說明擁有兩個映象Containers: 0 Running: 0 Paused: 0 Stopped: 0 Images: 2 Server Version: 17.12.0-ce Storage Driver: aufs Root Dir: /var/lib/docker/aufs Backing Filesystem: extfs Dirs: 2 Dirperm1 Supported: true Logging Driver: json-file Cgroup Driver: cgroupfs Plugins: Volume: local Network: bridge host macvlan null overlay Log: awslogs fluentd gcplogs gelf journald json-file logentries splunk syslog Swarm: inactive Runtimes: runc Default Runtime: runc Init Binary: docker-init containerd version: 89623f28b87a6004d4b785663257362d1658a729 runc version: b2567b37d7b75eb4cf325b77297b140ea686ce8f init version: 949e6fa Security Options: seccomp Profile: default Kernel Version: 4.9.60-linuxkit-aufs Operating System: Docker for Mac OSType: linux Architecture: x86_64 CPUs: 2 Total Memory: 1.952GiB Name: linuxkit-025000000001 ID: EPWI:4P5C:KBV6:2YHA:KPE5:VP57:BCUN:TSQE:FKIJ:ST3H:6YMY:YRZZ Docker Root Dir: /var/lib/docker Debug Mode (client): false Debug Mode (server): false HTTP Proxy: docker.for.mac.http.internal:3128 HTTPS Proxy: docker.for.mac.http.internal:3129 Registry: https://index.docker.io/v1/ Labels: Experimental: false Insecure Registries: 127.0.0.0/8 Registry Mirrors: http://c80e66a4.m.daocloud.io/ Live Restore Enabled: false
執行 docker images 檢視映象
編寫一個Dockerfile ,如下REPOSITORY TAG IMAGE ID CREATED SIZE busybox latest f9b6f7f7b9d3 36 hours ago 1.14MB centos latest ff426288ea90 8 days ago 207MB
# 以centos映象為基礎映象
From centos
# 在映象中執行建立目錄 /home/test/
RUN mkdir -p /home/test/
# 進入目錄
RUN cd /home/test/
# 將docker.sh 檔案拷貝到映象中的 /home/test/
ADD docker.sh /home/test/
# 增加執行許可權
RUN chmod +x /home/test/docker.sh
# 容器啟動時執行的操作
CMD /home/test/docker.sh
這個Dockerfile指明瞭基礎的映象,和將外部檔案拷入映象,以及使用該映象生成容器時需執行的操作,docker.sh 是一個簡單的shell 指令碼,主要用於測試 ,如下
將這兩個檔案放入到同一目錄下 ,到該目錄執行#!/bin/bash while true do sleep 1; curl '172.22.29.38:8088'; done
docker build -t docker-test .
命令執行結束出現
Successfully tagged docker-test:latest
說明映象執行成功,執行 docker images ,出現
REPOSITORY TAG IMAGE ID CREATED SIZE
docker-test latest a2eccd1c1018 44 seconds ago 207MB
busybox latest f9b6f7f7b9d3 36 hours ago 1.14MB
centos latest ff426288ea90 8 days ago 207MB
此時已經有docker-test 映象,說明映象已經制作成功啦