dokcer基础命令-详解

  1. 云栖社区>
  2. 博客>
  3. 正文

dokcer基础命令-详解

余二五 2017-11-15 21:52:00 浏览900
展开阅读全文

wKioL1eiIHzTQIFUAAAcSdHIOfQ852.png-wh_50

wKiom1eiIKGz6kFDAAB1PleyX0M711.png-wh_50

wKiom1eiIL2hse-9AAA19eCexZA881.png-wh_50

wKioL1eiINrxkQ-5AAA030lxmwI171.png-wh_50

Docker是否正确安装

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
[root@oldboy ~]# docker  info
Containers: 1
Images: 11
Storage Driver: aufs
 Root Dir: /var/lib/docker/aufs
 Backing Filesystem: extfs
 Dirs: 13
 Dirperm1 Supported: false
Execution Driver: native-0.2
Logging Driver: json-file
Kernel Version: 3.10.5-3.el6.x86_64
Operating System: <unknown>
CPUs: 1
Total Memory: 490 MiB
Name: oldboy
ID: GEKM:V4DM:4GEI:D64E:MYZC:AZ6B:HS2G:3LWR:BCP7:6DBC:3BGJ:YOJR
WARNING: No swap limit support
[root@oldboy ~]#
[root@oldboy ~]#

Docker帮助

1
2
3
4
5
6
[root@oldboy ~]# docker pull --help
Usage: docker pull [OPTIONS] NAME[:TAG|@DIGEST]
Pull an image or a repository from the registry
  -a, --all-tags=false    Download all tagged images in the repository
  --help=false            Print usage
[root@oldboy ~]#

Docker查询

1
2
3
4
docker   search   软件名称
     docker search  centos7
     docker  search  nginx
     docker  search  httpd

Docker拉取一个预建的镜像并运行

1
2
3
4
5
6
7
8
9
10
BusyBox是一个最小的Linux系统,它提供了主要的功能,不包含一些与GNU相关的功能和选项。
 
[root@oldboy ~]# docker pull busybox
latest: Pulling from busybox
4185ddbe03f8: Pull complete
b05baf071fd5: Pull complete
Digest: sha256:65ce39ce3eb0997074a460adfb568d0b9f0f6a4392d97b6035630c9d7bf92402
Status: Downloaded newer image for busybox:latest
[root@oldboy ~]# docker run busybox /bin/echo hello world
hello world

docker 基本操作命令启动删除保存

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
[root@oldboy ~]# sample=$(docker run -d busybox /bin/sh -c "while true;do echo docker;sleep 2;done")
[root@oldboy ~]# docker logs $sample   #docker  logs  查看job的当前状态
docker
docker
docker
docker
docker
docker
[root@oldboy ~]# docker stop $sample   #停止名为sample的容器
[root@oldboy ~]# docker restart  $sample   #重新启动sample的docker
[root@oldboy ~]# docker stop  $sample && docker  rm $sample    #删除一个docker必须要先停止
3b7f9c8dc5d9449564345a75436d5cc21a9a64e6a738fa70b44aeab6b20d83ba
3b7f9c8dc5d9449564345a75436d5cc21a9a64e6a738fa70b44aeab6b20d83ba
[root@oldboy ~]# sample=$(docker run -d busybox /bin/sh -c "while true;do echo docker;sleep 2;done")
[root@oldboy ~]# docker commit $sample jobs01
4737ce9e8877704f7985b3bb8d04f0e69f01da5d5fac5d5ce3edd1d9e599570c
[root@oldboy ~]# docker  images
REPOSITORY          TAG                 IMAGE ID            CREATED             VIRTUAL SIZE
jobs01              latest              4737ce9e8877        4 seconds ago       1.093 MB
centos              centos6             273a1eca2d3a        4 days ago          194.6 MB
<none>              <none>              3fbd5972aaac        4 days ago          196.7 MB
centos              6.8                 c51f770ba2ca        4 weeks ago         194.5 MB
busybox             latest              b05baf071fd5        5 weeks ago         1.093 MB
[root@oldboy ~]#

删除一个镜像

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
[root@oldboy ~]# docker  images
REPOSITORY          TAG                 IMAGE ID            CREATED             VIRTUAL SIZE
jobs01              latest              4737ce9e8877        18 minutes ago      1.093 MB
centos              centos6             273a1eca2d3a        4 days ago          194.6 MB
<none>              <none>              3fbd5972aaac        4 days ago          196.7 MB
centos              6.8                 c51f770ba2ca        4 weeks ago         194.5 MB
busybox             latest
[root@oldboy ~]# docker  rmi jobs01
Untagged: jobs01:latest
Deleted: 4737ce9e8877704f7985b3bb8d04f0e69f01da5d5fac5d5ce3edd1d9e599570c
[root@oldboy ~]# docker  images    
REPOSITORY          TAG                 IMAGE ID            CREATED             VIRTUAL SIZE
centos              centos6             273a1eca2d3a        4 days ago          194.6 MB
<none>              <none>              3fbd5972aaac        4 days ago          196.7 MB
centos              6.8                 c51f770ba2ca        4 weeks ago         194.5 MB
busybox             latest              b05baf071fd5        5 weeks ago         1.093 MB
[root@oldboy ~]#
[root@oldboy ~]# docker  rmi  -f jobs02   #强制删除一个镜像
Untagged: jobs02:latest
Deleted: 910fad104843559d4e5b908305b4dae7a71cf9bda6e99b296e8d73f77192b043
[root@oldboy ~]# docker  images        
REPOSITORY          TAG                 IMAGE ID            CREATED             VIRTUAL SIZE
centos              centos6             273a1eca2d3a        4 days ago          194.6 MB
<none>              <none>              3fbd5972aaac        4 days ago          196.7 MB
centos              6.8                 c51f770ba2ca        4 weeks ago         194.5 MB
busybox             latest              b05baf071fd5        5 weeks ago         1.093 MB
[root@oldboy ~]#

查看正在运行的docker和删除一个docker和启动一个已经停止的docker

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
[root@oldboy ~]# docker ps -a
CONTAINER ID        IMAGE               COMMAND                CREATED             STATUS                      PORTS               NAMES
d01eb9c6bfcc        busybox             "/bin/sh -c 'while t   3 minutes ago       Up 3 minutes                                    drunk_davinci      
0910014720e8        busybox             "/bin/sh -c 'while t   23 minutes ago      Up 23 minutes                                   drunk_meitner      
92b9a783fd63        busybox             "/bin/echo hello wol   47 minutes ago      Exited (0) 47 minutes ago                       hopeful_rosalind   
5ed9622fe692        busybox             "/bin/echo hello wor   52 minutes ago      Exited (0) 52 minutes ago                       reverent_mayer
[root@oldboy ~]# docker stop d01eb9c6bfcc
[root@oldboy ~]# docker ps -a           
CONTAINER ID        IMAGE               COMMAND                CREATED             STATUS                       PORTS               NAMES
d01eb9c6bfcc        busybox             "/bin/sh -c 'while t   4 minutes ago       Exited (137) 3 seconds ago                       drunk_davinci      
0910014720e8        busybox             "/bin/sh -c 'while t   24 minutes ago      Up 24 minutes                                    drunk_meitner      
92b9a783fd63        busybox             "/bin/echo hello wol   48 minutes ago      Exited (0) 48 minutes ago                        hopeful_rosalind   
5ed9622fe692        busybox             "/bin/echo hello wor   53 minutes ago      Exited (0) 53 minutes ago                        reverent_mayer
[root@oldboy ~]# docker start d01eb9c6bfcc
d01eb9c6bfcc
[root@oldboy ~]# docker ps -a
CONTAINER ID        IMAGE               COMMAND                CREATED             STATUS                            PORTS               NAMES
d01eb9c6bfcc        busybox             "/bin/sh -c 'while t   6 minutes ago       Up 2 seconds                                          drunk_davinci      
0910014720e8        busybox             "/bin/sh -c 'while t   26 minutes ago      Exited (137) About a minute ago                       drunk_meitner      
92b9a783fd63        busybox             "/bin/echo hello wol   50 minutes ago      Exited (0) 50 minutes ago                             hopeful_rosalind   
5ed9622fe692        busybox             "/bin/echo hello wor   55 minutes ago      Exited (0) 55 minutes ago                             reverent_mayer     
[root@oldboy ~]#

使用一个镜像执行一个容器,容器内执行hello world 输出,输出后结束容器关闭

1
2
3
[root@oldboy ~]# docker run busybox  /bin/echo  "hello world"
hello world
[root@oldboy ~]#

docker镜像推送到docker仓库

1
2
3
4
5
6
7
8
9
10
11
[root@oldboy ~]# docker  images
REPOSITORY          TAG                 IMAGE ID            CREATED             VIRTUAL SIZE
jobs03              latest              dd40474b2a4c        13 minutes ago      1.093 MB
centos              centos6             273a1eca2d3a        4 days ago          194.6 MB
centos              latest              d83a55af4e75        4 days ago          196.7 MB
centos              6.8                 c51f770ba2ca        4 weeks ago         194.5 MB
busybox             latest              b05baf071fd5        5 weeks ago         1.093 MB
[root@oldboy ~]# docker push jobs03
You cannot push a "root" repository. Please rename your repository to <user>/<repo> (ex: 123456/jobs03)
[root@oldboy ~]# docker tag jobs03   jb/jobs03
[root@oldboy ~]# docker push jb/jobs03









本文转自 小小三郎1 51CTO博客,原文链接:http://blog.51cto.com/wsxxsl/1834152,如需转载请自行联系原作者

网友评论

登录后评论
0/500
评论
余二五
+ 关注