Docker启动和运行什么区别?
运行只在第一次运行时使用,将镜像放到容器中,以后再次启动这个容器时,只需要使用命令“docker start”即可,而启动的作用是,重新启动已存在的镜像。
测试
比如我的docker里面有springboot项目的一个镜像
那么我使用docker run命令将他启动,使用docker ps 可以看到已经启动了一个springboot容器,然后我们停止它(docker stop)
再使用docker start启动它,再使用docker ps可以看到之前停止的已经启动了
[root@localhost ~]# docker images REPOSITORY TAG IMAGE ID CREATED SIZE springbootdocker latest 5fe8370f7f83 25 hours ago 677 MB daocloud.io/rabbitmq 3-management 1d0a5c8a8d4e 4 weeks ago 177 MB daocloud.io/library/tomcat latest 89481b5d9082 7 weeks ago 506 MB daocloud.io/library/mysql 5.5 d404d78aa797 3 months ago 205 MB daocloud.io/library/java latest d23bdf5b1b1b 2 years ago 643 MB docker.io/java 8 d23bdf5b1b1b 2 years ago 643 MB [root@localhost ~]# docker run --name springboot -p 8080:8080 -d 5f dd100a4c60a7a6606244873bc61a8a6f419361ab78fcd038d4baef3f38f05157 [root@localhost ~]# docker ps CONTAINER ID IMAGE COMMAND CREATED STATUS PORTS NAMES dd100a4c60a7 5f "java -Djava.secur..." 19 seconds ago Up 18 seconds 0.0.0.0:8080->8080/tcp springboot [root@localhost ~]# docker stop dd dd [root@localhost ~]# docker ps -a CONTAINER ID IMAGE COMMAND CREATED STATUS PORTS NAMES dd100a4c60a7 5f "java -Djava.secur..." 39 seconds ago Exited (143) 3 seconds ago springboot f3b181616dac 1d0a5c8a8d4e "docker-entrypoint..." 3 weeks ago Exited (255) 2 weeks ago 4369/tcp, 5671-5672/tcp, 0.0.0.0:5762->5762/tcp, 15671/tcp, 25672/tcp, 0.0.0.0:15672->15672/tcp myrabbit0 ea0a9cb0fe2f 89481b5d9082 "catalina.sh run" 4 weeks ago Exited (129) 4 weeks ago clever_leakey [root@localhost ~]# docker start dd dd [root@localhost ~]# docker ps CONTAINER ID IMAGE COMMAND CREATED STATUS PORTS NAMES dd100a4c60a7 5f "java -Djava.secur..." About a minute ago Up 2 seconds 0.0.0.0:8080->8080/tcp springboot [root@localhost ~]#
推荐教程:《Docker》