测试工程师Docker基础 (2)

三、docker常用命令 1、帮助命令 docker version #显示dokcer版本信息 docker info #显示docker的系统信息,包括镜像和容器数量 docker 命令 --help #帮助命令 2、镜像命令 docker images #查看所有本地主机上的镜像 docker search #搜索某个镜像 docker pull #下载镜像 docker rmi #删除镜像

docker images #查看所有本地主机上的镜像

[root@ecs-x-large-2-linux-20200305213344 ~]# docker images REPOSITORY TAG IMAGE ID CREATED SIZE docker.io/hello-world latest d1165f221234 7 hours ago 13.3 kB docker.io/nginx latest 35c43ace9216 2 weeks ago 133 MB #解释 #REPOSITORY 镜像的仓库源 #TAG 镜像标签 #IMAGE ID 镜像id #CREATED 镜像创建时间 #SIZE 镜像大小 #可选项 Options: -a, --all Show all images (default hides intermediate images)#查看所有镜像 -q, --quiet Only show numeric IDs #只显示镜像id [root@ecs-x-large-2-linux-20200305213344 ~]# docker images -aq #显示所有镜像id d1165f221234 35c43ace9216

docker pull #下载镜像

#下载镜像 docker pull 镜像名[:tag] 如果不写tag默认下载最新 [root@ecs-x-large-2-linux-20200305213344 ~]# docker pull redis Using default tag: latest Trying to pull repository docker.io/library/redis ... latest: Pulling from docker.io/library/redis 45b42c59be33: Already exists #分层下载 5ce2e937bf62: Pull complete 2a031498ff58: Pull complete 2f3d47096658: Pull complete 04f5cb8ac4c0: Pull complete 9ed141398658: Pull complete Digest: sha256:9a1a2bb9fd2bd8b2c15aaca44d8e6ba8bc448df9b7b8d7d24ba4b472e0da1b8a Status: Downloaded newer image for docker.io/redis:latest #镜像的真实地址

docker rmi #删除镜像

docker rmi -f 镜像id #删除指定的镜像 docker rmi -f 镜像id 镜像id #删除指定的镜像 docker rmi -f $(docker images -aq) #删除全部的镜像 3、容器命令

备注:我们有了镜像才能创建容器

docker run 镜像id #新建容器并启动 docker ps #列出所有运行的容器 docker rm 容器id #删除指定容器 docker start 容器id #启动容器 docker restart容器id #重启容器 docker stop 容器id #停止当前正在运行的容器 docker kill 容器id #强制停止当前容器 #查看容器所有命令 [root@ecs-x-large-2-linux-20200305213344 ~]# docker container Usage: docker container COMMAND Manage containers Options: --help Print usage Commands: attach Attach to a running container commit Create a new image from a container's changes cp Copy files/folders between a container and the local filesystem create Create a new container diff Inspect changes on a container's filesystem exec Run a command in a running container export Export a container's filesystem as a tar archive inspect Display detailed information on one or more containers kill Kill one or more running containers logs Fetch the logs of a container ls List containers pause Pause all processes within one or more containers port List port mappings or a specific mapping for the container prune Remove all stopped containers rename Rename a container restart Restart one or more containers rm Remove one or more containers run Run a command in a new container start Start one or more stopped containers stats Display a live stream of container(s) resource usage statistics stop Stop one or more running containers top Display the running processes of a container unpause Unpause all processes within one or more containers update Update configuration of one or more containers wait Block until one or more containers stop, then print their exit codes

新建容器并启动

docker runb [可选参数] image #参数说明 --name =”name“ #容器名字,用于区分不同的的容器 -d #后台运行 -it #使用交互模式运行,进入容器查看相关内容 -p #指定容器端口 -p 主机端口:容器端口 #测试-it [root@ecs-x-large-2-linux-20200305213344 ~]# docker run -it 300e315adb2f /bin/bash [root@9f5b41ce646c /]# ls bin dev etc home lib lib64 lost+found media mnt opt proc root run sbin srv sys tmp usr var [root@9f5b41ce646c /]# exit #退出容器 exit #测试 --name -p -d [root@ecs-x-large-2-linux-20200305213344 ~]# docker run --name nginx01 -d -p 3334:80 35c43ace9216 cacf7a960d29dc24755f6b9896aaa85f2e9f902ff7f620470c907acf5e17bd7a [root@ecs-x-large-2-linux-20200305213344 ~]# curl localhost:3334 <!DOCTYPE html> <html> <head> <title>Welcome to nginx!</title> #成功访问3334端口 <style> body { width: 35em; margin: 0 auto; font-family: Tahoma, Verdana, Arial, sans-serif; } </style> </head> <body> <h1>Welcome to nginx!</h1> <p>If you see this page, the nginx web server is successfully installed and working. Further configuration is required.</p> <p>For online documentation and support please refer to <a href="http://nginx.org/">nginx.org</a>.<br/> Commercial support is available at <a href="http://nginx.com/">nginx.com</a>.</p> <p><em>Thank you for using nginx.</em></p> </body> </html> #测试是否后台运行 [root@ecs-x-large-2-linux-20200305213344 ~]# docker ps CONTAINER ID IMAGE COMMAND CREATED STATUS PORTS NAMES cacf7a960d29 35c43ace9216 "/docker-entrypoin..." About a minute ago Up About a minute 0.0.0.0:3334->80/tcp nginx01

内容版权声明:除非注明,否则皆为本站原创文章。

转载注明出处:https://www.heiqu.com/zyffwy.html