Docker是否正确安装
[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帮助
[root@oldboy ~]# docker pull --help Usage: docker pull [OPTIONS] NAME[:TAG|@DIGEST] Pull an p_w_picpath or a repository from the registry -a, --all-tags=false Download all tagged p_w_picpaths in the repository --help=false Print usage [root@oldboy ~]#
Docker查询
docker search 软件名称 docker search centos7 docker search nginx docker search httpd
Docker拉取一个预建的镜像并运行
BusyBox是一个最小的Linux系统,它提供了主要的功能,不包含一些与GNU相关的功能和选项。 [root@oldboy ~]# docker pull busybox latest: Pulling from busybox 4185ddbe03f8: Pull complete b05baf071fd5: Pull complete Digest: sha256:65ce39ce3eb0997074a460adfb568d0b9f0f6a4392d97b6035630c9d7bf92402 Status: Downloaded newer p_w_picpath for busybox:latest [root@oldboy ~]# docker run busybox /bin/echo hello world hello world
docker 基本操作命令启动删除保存
[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 p_w_picpaths 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 ~]#
删除一个镜像
[root@oldboy ~]# docker p_w_picpaths 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 p_w_picpaths 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 p_w_picpaths 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
[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 输出,输出后结束容器关闭
[root@oldboy ~]# docker run busybox /bin/echo "hello world" hello world [root@oldboy ~]#
docker镜像推送到docker仓库
[root@oldboy ~]# docker p_w_picpaths 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
转载于:https://blog.51cto.com/wsxxsl/1834152