概述
docker pull : 从镜像仓库中拉取或者更新指定镜像
docker pull [OPTIONS] NAME[:TAG|@DIGEST]
[root@node2 ~]# docker login -u wangjinhuai
Password:
Login Succeeded
[root@node2 ~]# ls
anaconda-ks.cfg
initial-setup-ks.cfg
original-ks.cfg
[root@node2 ~]# docker tag docker.io/busybox:latest docker.io/wangjinhuai/mydata:v0.1.0
[root@node2 ~]# docker images
REPOSITORY
TAG
IMAGE ID
CREATED
SIZE
docker.io/busybox
latest
59788edf1f3e
2 months ago
1.15 MB
docker.io/wangjinhuai/mydata
v0.1.0
59788edf1f3e
2 months ago
1.15 MB
[root@node2 ~]# docker push docker.io/wangjinhuai/mydata:v0.1.0
The push refers to a repository [docker.io/wangjinhuai/mydata]
8a788232037e: Mounted from library/busybox
v0.1.0: digest:
sha256:915f390a8912e16d4beb8689720a17348f3f6d1a7b659697df850ab625ea29d5 size: 527
[root@node2 ~]#
[root@node2 ~]# docker pull docker.io/wangjinhuai/busybox:v0.1.0
Trying to pull repository docker.io/wangjinhuai/busybox ...
v0.1.0: Pulling from docker.io/wangjinhuai/busybox
Digest: sha256:915f390a8912e16d4beb8689720a17348f3f6d1a7b659697df850ab625ea29d5
Status: Downloaded newer image for docker.io/wangjinhuai/busybox:v0.1.0
[root@node2 ~]# docker images
REPOSITORY
TAG
IMAGE ID
CREATED
SIZE
docker.io/busybox
latest
59788edf1f3e
2 months ago
1.15 MB
docker.io/wangjinhuai/busybox
v0.1.0
59788edf1f3e
2 months ago
1.15 MB
docker.io/wangjinhuai/mydata
v0.1.0
59788edf1f3e
2 months ago
1.15 MB
[root@node2 ~]#
[root@node2 ~]# docker run --name test -it docker.io/wangjinhuai/busybox:v0.1.0
/ # mkdir /data/html
mkdir: can't create directory '/data/html': No such file or directory
/ # mkdir /data/html -p
/ # vi /data/html/index.html
<h1>Busybox Server</h1>
/ # httpd -h /data/html/
/ # netstat -tunl
Active Internet connections (only servers)
Proto Recv-Q Send-Q Local Address
Foreign Address
State
tcp
0
0 :::80
:::*
LISTEN
/ # ifconfig
eth0
Link encap:Ethernet
HWaddr 02:42:AC:11:00:02
inet addr:172.17.0.2
Bcast:0.0.0.0
Mask:255.255.0.0
inet6 addr: fe80::42:acff:fe11:2/64 Scope:Link
UP BROADCAST RUNNING MULTICAST
MTU:1500
Metric:1
RX packets:8 errors:0 dropped:0 overruns:0 frame:0
TX packets:8 errors:0 dropped:0 overruns:0 carrier:0
collisions:0 txqueuelen:0
RX bytes:648 (648.0 B)
TX bytes:648 (648.0 B)
lo
Link encap:Local Loopback
inet addr:127.0.0.1
Mask:255.0.0.0
inet6 addr: ::1/128 Scope:Host
UP LOOPBACK RUNNING
MTU:65536
Metric:1
RX packets:0 errors:0 dropped:0 overruns:0 frame:0
TX packets:0 errors:0 dropped:0 overruns:0 carrier:0
collisions:0 txqueuelen:1000
RX bytes:0 (0.0 B)
TX bytes:0 (0.0 B)
/ #
客户端测试:
[root@node2 ~]# curl http://172.17.0.2
<h1>Busybox Server</h1>
[root@node2 ~]#
docker commit :从容器创建一个新的镜像。
syntax:
docker commit [OPTIONS] CONTAINER [REPOSITORY[:TAG]]
OPTIONS说明:
-a :提交的镜像作者;
-c :使用Dockerfile指令来创建镜像;
-m :提交时的说明文字;
-p :在commit时,将容器暂停。
[root@node2 ~]#docker commit -p -a "wangjinhuai" busybox docker.io/wangjinhuai/busybox:v0.1.0-httpd
sha256:83d64f9e55c76815c83a5d12cab8b22bd86b4b348a6a4912d8b0da99b2aed7bb
[root@node2 ~]# docker images
REPOSITORY
TAG
IMAGE ID
CREATED
SIZE
docker.io/wangjinhuai/busybox
v0.1.0-httpd
83d64f9e55c7
10 seconds ago
1.15 MB
docker.io/wangjinhuai/busybox
v0.1.0
59788edf1f3e
2 months ago
1.15 MB
docker.io/wangjinhuai/mydata
v0.1.0
59788edf1f3e
2 months ago
1.15 MB
docker.io/busybox
latest
59788edf1f3e
2 months ago
1.15 MB
[root@node2 ~]# docker run --name test -d docker.io/wangjinhuai/busybox:v0.1.0-httpd /bin/httpd -f -h /data/html
4b6c65bb28a907735985c5a51f07ec346d2f0df0a312ef1030eb706addc94e54
[root@node2 ~]# docker ps
CONTAINER ID
IMAGE
COMMAND
CREATED
STATUS
PORTS
NAMES
4b6c65bb28a9
docker.io/wangjinhuai/busybox:v0.1.0-httpd
"/bin/httpd -f -h ..."
4 seconds ago
Up 4 seconds
test
[root@node2 ~]#
测试:
[root@node2 ~]# docker inspect --format='{{range .NetworkSettings.Networks}}{{.IPAddress}}{{end}}' test
172.17.0.2
[root@node2 ~]#
[root@node2 ~]# curl http://172.17.0.2
<h1>Busybox Server</h1>
[root@node2 ~]# curl http://172.17.0.2
<h1>Busybox Server</h1>
示例2:
[root@node2 ~]# docker commit -a "wangjinhuai" -c 'CMD ["/bin/httpd","-f","-h","/data/html"]' test docker.io/wangjinhuai/busybox:v0.1.1-httpd
sha256:780144947cd3d1da9f6363d30e7d4fac77c7dc715ac970daf24cdf362afb9d9d
[root@node2 ~]# docker images
REPOSITORY
TAG
IMAGE ID
CREATED
SIZE
docker.io/wangjinhuai/busybox
v0.1.1-httpd
780144947cd3
14 seconds ago
1.15 MB
docker.io/wangjinhuai/busybox
v0.1.0-httpd
83d64f9e55c7
28 minutes ago
1.15 MB
[root@node2 ~]# docker run --name test2 -d docker.io/wangjinhuai/busybox:v0.1.1-httpd
7250d04f7094e00ebb044cd801eab6431701d806fb95073d2677d13052661e5c
[root@node2 ~]# docker ps
CONTAINER ID
IMAGE
COMMAND
CREATED
STATUS
PORTS
NAMES
7250d04f7094
docker.io/wangjinhuai/busybox:v0.1.1-httpd
"/bin/httpd -f -h ..."
10 seconds ago
Up 9 seconds
test2
4b6c65bb28a9
docker.io/wangjinhuai/busybox:v0.1.0-httpd
"/bin/httpd -f -h ..."
22 minutes ago
Up 22 minutes
test
[root@node2 ~]# docker inspect --format='{{range .NetworkSettings.Networks}}{{.IPAddress}}{{end}}' test2
172.17.0.3
[root@node2 ~]# curl http://172.17.0.3
<h1>Busybox Server</h1>
[root@node2 ~]# curl http://172.17.0.3
<h1>Busybox Server</h1>
[root@node2 ~]#
[root@node2 ~]# docker exec test2 ps
PID
USER
TIME
COMMAND
1 root
0:00 /bin/httpd -f -h /data/html
8 root
0:00 ps
[root@node2 ~]#
示例3:
[root@node2 ~]# docker pull docker.io/centos
Using default tag: latest
Trying to pull repository docker.io/library/centos ...
latest: Pulling from docker.io/library/centos
a02a4930cb5d: Pull complete
Digest: sha256:184e5f35598e333bfa7de10d8fb1cebb5ee4df5bc0f970bf2b1e7c7345136426
Status: Downloaded newer image for docker.io/centos:latest
[root@node2 ~]# docke images
bash: docke: command not found...
[root@node2 ~]# docker images
REPOSITORY
TAG
IMAGE ID
CREATED
SIZE
docker.io/wangjinhuai/busybox
v0.1.1-httpd
780144947cd3
12 minutes ago
1.15 MB
docker.io/wangjinhuai/busybox
v0.1.0-httpd
83d64f9e55c7
40 minutes ago
1.15 MB
docker.io/centos
latest
1e1148e4cc2c
2 weeks ago
202 MB
[root@node2 ~]# docker run --name centos -it docker.io/centos:latest
[root@2c7f944683be /]# ls
anaconda-post.log
bin
dev
etc
home
lib
lib64
media
mnt
opt
proc
root
run
sbin
srv
sys
tmp
usr
var
[root@2c7f944683be /]# yum -y install net-tools
[root@2c7f944683be /]# yum -y install epel-release
[root@2c7f944683be /]# yum -y install nginx
[root@2c7f944683be /]# vi /etc/nginx/nginx.conf
daemon off;
[root@2c7f944683be /]# nginx -t
nginx: the configuration file /etc/nginx/nginx.conf syntax is ok
nginx: configuration file /etc/nginx/nginx.conf test is successful
[root@2c7f944683be /]# nginx
[root@node2 ~]# yum clean all
Loaded plugins: fastestmirror, langpacks
Cleaning repos: base epel extras updates
Cleaning up everything
Maybe you want: rm -rf /var/cache/yum, to also free up space taken by orphaned data from disabled or removed repos
Cleaning up list of fastest mirrors
[root@node2 ~]# docker commit -a "wangjinhuai" -c 'CMD ["/usr/sbin/nginx"]' centos docker.io/wangjinhuai/nginx:v0.1.0
sha256:da9656c8d6b1e86bcd0f84fc52f77f7cbb303cd32e64fc6135b9df13efd09367
[root@node2 ~]# docker images
REPOSITORY
TAG
IMAGE ID
CREATED
SIZE
docker.io/wangjinhuai/nginx
v0.1.0
da9656c8d6b1
12 seconds ago
394 MB
docker.io/wangjinhuai/busybox
v0.1.1-httpd
780144947cd3
27 minutes ago
1.15 MB
docker.io/wangjinhuai/busybox
v0.1.0-httpd
83d64f9e55c7
55 minutes ago
1.15 MB
docker.io/centos
latest
1e1148e4cc2c
2 weeks ago
202 MB
docker.io/busybox
latest
59788edf1f3e
2 months ago
1.15 MB
docker.io/wangjinhuai/busybox
v0.1.0
59788edf1f3e
2 months ago
1.15 MB
docker.io/wangjinhuai/mydata
v0.1.0
59788edf1f3e
2 months ago
1.15 MB
[root@node2 ~]# docker run --name nginx -d docker.io/wangjinhuai/nginx:v0.1.0
1b204aac78435165f601a317f26fc830efec628bccbc807c61bfbd7bdf90826a
[root@node2 ~]# docker ps
CONTAINER ID
IMAGE
COMMAND
CREATED
STATUS
PORTS
NAMES
1b204aac7843
docker.io/wangjinhuai/nginx:v0.1.0
"/usr/sbin/nginx"
9 seconds ago
Up 7 seconds
nginx
2c7f944683be
docker.io/centos:latest
"/bin/bash"
13 minutes ago
Up 13 minutes
centos
7250d04f7094
docker.io/wangjinhuai/busybox:v0.1.1-httpd
"/bin/httpd -f -h ..."
24 minutes ago
Up 24 minutes
test2
4b6c65bb28a9
docker.io/wangjinhuai/busybox:v0.1.0-httpd
"/bin/httpd -f -h ..."
46 minutes ago
Up 46 minutes
test
[root@node2 ~]#
[root@node2 ~]# docker inspect --format='{{range .NetworkSettings.Networks}}{{.IPAddress}}{{end}}' test
172.17.0.5
[root@node2 ~]# curl httP://172.17.0.5
save和load用法;
[root@node2 ~]# docker run --name test -d -it -v /data/html docker.io/wangjinhuai/busybox:v0.1.1-httpd
bbc4223db8d6cb3e78ec7aa71e1d376e2619f9a82843af2f8aaeb98e5cb94b22
[root@node2 ~]# curl http://172.17.0.2
<h1>Busybox Server</h1>
[root@node2 ~]# vi /var/lib/docker/volumes/4d394521d3b2a93405cbf28207bc4855e0153ec8349379699ccc7da006520055/_data/index.html
<h1>Host Page</h1>
[root@node2 ~]# curl http://172.17.0.2
<h1>Host Page</h1>
[root@node2 ~]#
[root@node2 ~]# docker save -o /root/nginx-v0.1.0.tar da9656c8d6b1
[root@node2 ~]# ll -h
total 388M
-rw-------. 1 root root 1.5K Nov 24 22:18 anaconda-ks.cfg
-rw-r--r--. 1 root root 1.6K Nov 24 22:25 initial-setup-ks.cfg
-rw-------. 1 root root 388M Dec 22 21:45 nginx-v0.1.0.tar
-rw-------. 1 root root 1.5K Nov 24 22:18 original-ks.cfg
[root@node2 ~]#
[root@node2 ~]# docker images
REPOSITORY
TAG
IMAGE ID
CREATED
SIZE
docker.io/wangjinhuai/nginx
v0.1.0
da9656c8d6b1
9 minutes ago
394 MB
[root@node2 ~]# scp nginx-v0.1.0.tar 192.168.170.30:/tmp/
The authenticity of host '192.168.170.30 (192.168.170.30)' can't be established.
ECDSA key fingerprint is SHA256:52p8v2K/Ezs2KWUkhEo8BYwM5P/lzO1+a/OpYEdzwV0.
ECDSA key fingerprint is MD5:cf:49:09:fc:8f:ed:6a:2a:57:61:8e:f9:14:7e:62:7f.
Are you sure you want to continue connecting (yes/no)? yes
Warning: Permanently added '192.168.170.30' (ECDSA) to the list of known hosts.
root@192.168.170.30's password:
nginx-v0.1.0.tar
100%
387MB
35.0MB/s
00:11
[root@node2 ~]#
[root@node5 ~]# docker load -i /tmp/nginx-v0.1.0.tar
6109ece4eeb3: Loading layer [==================================================>]
196 MB/196 MB
Loaded image ID: sha256:da9656c8d6b1e86bcd0f84fc52f77f7cbb303cd32e64fc6135b9df13efd09367
[root@node5 ~]# docker images
REPOSITORY
TAG
IMAGE ID
CREATED
SIZE
<none>
<none>
da9656c8d6b1
21 minutes ago
394 MB
[root@node5 ~]# docker tag da9656c8d6b1 docker.io/wangjinhuai/nginx:v0.1.1
[root@node5 ~]# docker images
REPOSITORY
TAG
IMAGE ID
CREATED
SIZE
docker.io/wangjinhuai/nginx
v0.1.1
da9656c8d6b1
24 minutes ago
394 MB
[root@node2 ~]# docker kill test
test
[root@node2 ~]# mkdir /appdata/html -pv
mkdir: created directory ‘/appdata’
mkdir: created directory ‘/appdata/html’
[root@node2 ~]# vi /appdata/html/inde.html
<h1>Appdata Test Page</h1>
[root@node2 ~]# docker run --name test -d -it -v /appdata/html:/data/html docker.io/wangjinhuai/busybox:v0.1.1-httpd
1039b7424485496c1e16a4b8ece7013a38698e3d492d1c5280b10d7c4731af61
[root@node2 ~]# curl http://172.17.0.2
<h1>Appdata Test Page</h1>
[root@node2 ~]#
Sharing volumes
容器之间做共享卷有2种方式:
(1)多个容器的卷使用同一个主机目录,例如:
~]# docker run –it --name c1 -v /docker/volumes/v1:/data busybox
~]# docker run –it --name c2 -v /docker/volumes/v1:/data busybox
(2)复制使用其它容器的卷,为docker run命令使用--volumes-from选项 ,例如:
~]# docker run -it --name bbox1 -v /docker/volumes/v1:/data busybox
~]# docker run -it --name bbox2 --volumes-from bbox1 busybox
[root@node2 ~]# cat /appdata/html/index.html
<h1>Appdata Test Page</h1>
[root@node2 ~]# docker run --name test -d -it -v /appdata/html:/data/html docker.io/wangjinhuai/busybox:v0.1.1-httpd
8444d700bcc32c11e254bfd258143938e4b1eeb099e02333fd44dc1ead64cb5e
[root@node2 ~]# docker images
REPOSITORY
TAG
IMAGE ID
CREATED
SIZE
docker.io/wangjinhuai/nginx
v0.1.0
da9656c8d6b1
About an hour ago
394 MB
docker.io/wangjinhuai/busybox
v0.1.1-httpd
780144947cd3
About an hour ago
1.15 MB
docker.io/wangjinhuai/busybox
v0.1.0-httpd
83d64f9e55c7
2 hours ago
1.15 MB
docker.io/centos
latest
1e1148e4cc2c
2 weeks ago
202 MB
docker.io/busybox
latest
59788edf1f3e
2 months ago
1.15 MB
docker.io/wangjinhuai/busybox
v0.1.0
59788edf1f3e
2 months ago
1.15 MB
docker.io/wangjinhuai/mydata
v0.1.0
59788edf1f3e
2 months ago
1.15 MB
[root@node2 ~]# docker run
--name test1 -it --rm --volumes-from test docker.io/wangjinhuai/busybox:v0.1.0
/ # ls /data/html/
index.html
/ # cat /data/html/index.html
<h1>Appdata Test Page</h1>
/ #
[root@node2 ~]# docker run --name test2 -d -it -v /appdata/html:/data/html docker.io/wangjinhuai/busybox:v0.1.1-httpd
cb8c80e11b27465f8beaccbfbedfe97e1dc61bd3c363d53928e68da333dff933
[root@node2 ~]# docker ps
CONTAINER ID
IMAGE
COMMAND
CREATED
STATUS
PORTS
NAMES
cb8c80e11b27
docker.io/wangjinhuai/busybox:v0.1.1-httpd
"/bin/httpd -f -h ..."
17 seconds ago
Up 16 seconds
test2
4156a95aeca6
docker.io/wangjinhuai/busybox:v0.1.0
"sh"
5 minutes ago
Up 5 minutes
test1
8444d700bcc3
docker.io/wangjinhuai/busybox:v0.1.1-httpd
"/bin/httpd -f -h ..."
7 minutes ago
Up 7 minutes
test
1b204aac7843
docker.io/wangjinhuai/nginx:v0.1.0
"/usr/sbin/nginx"
About an hour ago
Up About an hour
nginx
2c7f944683be
docker.io/centos:latest
"/bin/bash"
About an hour ago
Up About an hour
centos
[root@node2 ~]# docker inspect --format='{{range .NetworkSettings.Networks}}{{.IPAddress}}{{end}}' test
172.17.0.2
[root@node2 ~]# docker inspect --format='{{range .NetworkSettings.Networks}}{{.IPAddress}}{{end}}' test1
172.17.0.3
[root@node2 ~]# docker inspect --format='{{range .NetworkSettings.Networks}}{{.IPAddress}}{{end}}' test2
172.17.0.6
[root@node2 ~]# curl http://172.17.0.6
<h1>Appdata Test Page</h1>
[root@node2 ~]# curl http://172.17.0.2
<h1>Appdata Test Page</h1>
最后
以上就是从容乌龟为你收集整理的Docker images制作的全部内容,希望文章能够帮你解决Docker images制作所遇到的程序开发问题。
如果觉得靠谱客网站的内容还不错,欢迎将靠谱客网站推荐给程序员好友。
本图文内容来源于网友提供,作为学习参考使用,或来自网络收集整理,版权属于原作者所有。
发表评论 取消回复