docker学习笔记2——常用的操作

  1)、镜像操作

 

操作 命令 说明
检索 docker search 关键字 eg:docker search redis 我们经常去docker hub上检索镜像的详细信息,如镜像的TAG。
拉取 docker pull 镜像名:tag :tag是可选的,tag表示标签,多为软件的版本,默认是latest
列表 docker images 查看所有本地镜像
删除 docker rmi image-id 删除指定的本地镜像

  官网可以使用https://hub.docker.com/ ,国内可以使用阿里云、或者网易云。

    1、搜索镜像 

[root@localhost ~]# docker search mysql

    docker学习笔记2——常用的操作_第1张图片

    2、拉取镜像

[root@localhost ~]# docker pull mysql

  docker学习笔记2——常用的操作_第2张图片 

  拉取指定版本的镜像

[root@localhost ~]# docker pull mysql:5.5

  docker学习笔记2——常用的操作_第3张图片

  3、查看本地所有镜像

[root@localhost ~]# docker images

  

  4、删除镜像,根据镜像id删除

 

删除命令,[root@localhost ~]# docker rmi d404d78aa797,根据docker images 查询出IMAGE ID删除镜像。

docker学习笔记2——常用的操作_第4张图片

 

 

 

  2)、容器操作(操作列表懒得制作了,附着一个尚硅谷docker操作列表说明)

    docker学习笔记2——常用的操作_第5张图片

 

 

 

 

   1、根据镜像启动容器

[root@localhost ~]# docker run --name mytomcat -d tomcat:latest

  注:--name后面参数为运行容器自定义名称(亦可以不指定自定义名称),-d表示后台运行(后面参数为镜像名称),冒号后面参数为tag号,如:latest表示最新的版本(最后更新的版本)可以忽略不写,本人在这里为了更直观的说明所以加上了,一般不是最新版本必须加上tag号来运行容器。

  2、查看正在运行的容器

 

[root@localhost ~]# docker ps

 

 

   3、停止运行中的容器

[root@localhost ~]# docker stop adc48bc0a25a

 

 

   

[root@localhost ~]# docker ps -a                        #可查看所有的容器包括已退出的容器,状态为Exited表示已退出的容器

 

 

   亦可使用以下命令根据CONTAINER ID将容器重新启动

[root@localhost ~]# docker start adc48bc0a25a

  4、停止后的容器已经无用可以删除,使用以下命令根据CONTAINER ID操作:

[root@localhost ~]# docker rm  adc48bc0a25a

 

 

   再次使用docker ps -a查看所有的容器会发现已删除的tomcat容器已不存在

 

 

   5、将虚拟机端口映射到容器端口,以tomcat为例启动一个做了端口映射的tomcat

[root@localhost ~]# docker run -d -p 8888:8080 tomcat #-d表示后台运行,-p表示映射端口,其中8888表示虚拟机端口,8080表示容器tomcat端口
‐d:后台运行
‐p: 将主机的端口映射到容器的一个端口 主机端口:容器内部的端口 (再次说明)

 

   6、此时可以通过虚拟机IP加上虚拟机端口号访问tomcat,如果不能访问请自行百度linux关闭防火墙,或者开放执行端口。

docker学习笔记2——常用的操作_第6张图片

 

 

 

    7、查看容器启动日志

[root@localhost ~]# docker logs 98c3fb8fd426 #根据CONTAINER ID查看
[root@localhost ~]# docker logs 98c3fb8fd426
14-Sep-2019 15:58:31.313 INFO [main] org.apache.catalina.startup.VersionLoggerListener.log Server version:        Apache Tomcat/8.5.45
14-Sep-2019 15:58:31.421 INFO [main] org.apache.catalina.startup.VersionLoggerListener.log Server built:          Aug 14 2019 22:21:25 UTC
14-Sep-2019 15:58:31.421 INFO [main] org.apache.catalina.startup.VersionLoggerListener.log Server number:         8.5.45.0
14-Sep-2019 15:58:31.428 INFO [main] org.apache.catalina.startup.VersionLoggerListener.log OS Name:               Linux
14-Sep-2019 15:58:31.428 INFO [main] org.apache.catalina.startup.VersionLoggerListener.log OS Version:            3.10.0-957.el7.x86_64
14-Sep-2019 15:58:31.428 INFO [main] org.apache.catalina.startup.VersionLoggerListener.log Architecture:          amd64
14-Sep-2019 15:58:31.428 INFO [main] org.apache.catalina.startup.VersionLoggerListener.log Java Home:             /usr/local/openjdk-8/jre
14-Sep-2019 15:58:31.428 INFO [main] org.apache.catalina.startup.VersionLoggerListener.log JVM Version:           1.8.0_222-b10
14-Sep-2019 15:58:31.429 INFO [main] org.apache.catalina.startup.VersionLoggerListener.log JVM Vendor:            Oracle Corporation
14-Sep-2019 15:58:31.429 INFO [main] org.apache.catalina.startup.VersionLoggerListener.log CATALINA_BASE:         /usr/local/tomcat
14-Sep-2019 15:58:31.429 INFO [main] org.apache.catalina.startup.VersionLoggerListener.log CATALINA_HOME:         /usr/local/tomcat
14-Sep-2019 15:58:31.429 INFO [main] org.apache.catalina.startup.VersionLoggerListener.log Command line argument: -Djava.util.logging.config.file=/usr/local/tomcat/conf/logging.properties
14-Sep-2019 15:58:31.430 INFO [main] org.apache.catalina.startup.VersionLoggerListener.log Command line argument: -Djava.util.logging.manager=org.apache.juli.ClassLoaderLogManager
14-Sep-2019 15:58:31.430 INFO [main] org.apache.catalina.startup.VersionLoggerListener.log Command line argument: -Djdk.tls.ephemeralDHKeySize=2048
14-Sep-2019 15:58:31.430 INFO [main] org.apache.catalina.startup.VersionLoggerListener.log Command line argument: -Djava.protocol.handler.pkgs=org.apache.catalina.webresources
14-Sep-2019 15:58:31.430 INFO [main] org.apache.catalina.startup.VersionLoggerListener.log Command line argument: -Dorg.apache.catalina.security.SecurityListener.UMASK=0027
14-Sep-2019 15:58:31.430 INFO [main] org.apache.catalina.startup.VersionLoggerListener.log Command line argument: -Dignore.endorsed.dirs=
14-Sep-2019 15:58:31.430 INFO [main] org.apache.catalina.startup.VersionLoggerListener.log Command line argument: -Dcatalina.base=/usr/local/tomcat
14-Sep-2019 15:58:31.430 INFO [main] org.apache.catalina.startup.VersionLoggerListener.log Command line argument: -Dcatalina.home=/usr/local/tomcat
14-Sep-2019 15:58:31.431 INFO [main] org.apache.catalina.startup.VersionLoggerListener.log Command line argument: -Djava.io.tmpdir=/usr/local/tomcat/temp
14-Sep-2019 15:58:31.431 INFO [main] org.apache.catalina.core.AprLifecycleListener.lifecycleEvent Loaded APR based Apache Tomcat Native library [1.2.23] using APR version [1.5.2].
14-Sep-2019 15:58:31.431 INFO [main] org.apache.catalina.core.AprLifecycleListener.lifecycleEvent APR capabilities: IPv6 [true], sendfile [true], accept filters [false], random [true].
14-Sep-2019 15:58:31.431 INFO [main] org.apache.catalina.core.AprLifecycleListener.lifecycleEvent APR/OpenSSL configuration: useAprConnector [false], useOpenSSL [true]
14-Sep-2019 15:58:31.442 INFO [main] org.apache.catalina.core.AprLifecycleListener.initializeSSL OpenSSL successfully initialized [OpenSSL 1.1.0k  28 May 2019]
14-Sep-2019 15:58:32.134 INFO [main] org.apache.coyote.AbstractProtocol.init Initializing ProtocolHandler ["http-nio-8080"]
14-Sep-2019 15:58:32.164 INFO [main] org.apache.tomcat.util.net.NioSelectorPool.getSharedSelector Using a shared selector for servlet write/read
14-Sep-2019 15:58:32.211 INFO [main] org.apache.coyote.AbstractProtocol.init Initializing ProtocolHandler ["ajp-nio-8009"]
14-Sep-2019 15:58:32.235 INFO [main] org.apache.tomcat.util.net.NioSelectorPool.getSharedSelector Using a shared selector for servlet write/read
14-Sep-2019 15:58:32.238 INFO [main] org.apache.catalina.startup.Catalina.load Initialization processed in 4413 ms
14-Sep-2019 15:58:32.426 INFO [main] org.apache.catalina.core.StandardService.startInternal Starting service [Catalina]
14-Sep-2019 15:58:32.427 INFO [main] org.apache.catalina.core.StandardEngine.startInternal Starting Servlet Engine: Apache Tomcat/8.5.45
14-Sep-2019 15:58:32.486 INFO [localhost-startStop-1] org.apache.catalina.startup.HostConfig.deployDirectory Deploying web application directory [/usr/local/tomcat/webapps/ROOT]
14-Sep-2019 15:58:33.996 INFO [localhost-startStop-1] org.apache.catalina.startup.HostConfig.deployDirectory Deployment of web application directory [/usr/local/tomcat/webapps/ROOT] has finished in [1,503] ms
14-Sep-2019 15:58:33.997 INFO [localhost-startStop-1] org.apache.catalina.startup.HostConfig.deployDirectory Deploying web application directory [/usr/local/tomcat/webapps/docs]
14-Sep-2019 15:58:34.115 INFO [localhost-startStop-1] org.apache.catalina.startup.HostConfig.deployDirectory Deployment of web application directory [/usr/local/tomcat/webapps/docs] has finished in [119] ms
14-Sep-2019 15:58:34.115 INFO [localhost-startStop-1] org.apache.catalina.startup.HostConfig.deployDirectory Deploying web application directory [/usr/local/tomcat/webapps/examples]
14-Sep-2019 15:58:36.190 INFO [localhost-startStop-1] org.apache.catalina.startup.HostConfig.deployDirectory Deployment of web application directory [/usr/local/tomcat/webapps/examples] has finished in [2,075] ms
14-Sep-2019 15:58:36.190 INFO [localhost-startStop-1] org.apache.catalina.startup.HostConfig.deployDirectory Deploying web application directory [/usr/local/tomcat/webapps/host-manager]
14-Sep-2019 15:58:36.289 INFO [localhost-startStop-1] org.apache.catalina.startup.HostConfig.deployDirectory Deployment of web application directory [/usr/local/tomcat/webapps/host-manager] has finished in [99] ms
14-Sep-2019 15:58:36.289 INFO [localhost-startStop-1] org.apache.catalina.startup.HostConfig.deployDirectory Deploying web application directory [/usr/local/tomcat/webapps/manager]
14-Sep-2019 15:58:36.343 INFO [localhost-startStop-1] org.apache.catalina.startup.HostConfig.deployDirectory Deployment of web application directory [/usr/local/tomcat/webapps/manager] has finished in [54] ms
14-Sep-2019 15:58:36.357 INFO [main] org.apache.coyote.AbstractProtocol.start Starting ProtocolHandler ["http-nio-8080"]
14-Sep-2019 15:58:36.388 INFO [main] org.apache.coyote.AbstractProtocol.start Starting ProtocolHandler ["ajp-nio-8009"]
14-Sep-2019 15:58:36.396 INFO [main] org.apache.catalina.startup.Catalina.start Server startup in 4158 ms

    至此,docker镜像操作和容器操作已经通过图文并茂总结完毕,当然涉及其他更多的操作更多命令参看https://docs.docker.com/engine/reference/commandline/docker/可以参考每一个镜像的文档 ,这里就不一一的演示了,本人也是新手一边学习一边记录,有不足之处请各位大神海涵。


 

转载于:https://www.cnblogs.com/3wweblogs-a/p/11520877.html

你可能感兴趣的:(docker学习笔记2——常用的操作)