当前位置:   article > 正文

Docker学习(04)——容器命令_docker启动tomcat容器失败:exited (1) 2 minutes ago

docker启动tomcat容器失败:exited (1) 2 minutes ago

1. 下载镜像

docker pull centos

2. 新建容器并启动

docker run [可选参数] image

参数说明:

  1. --name="Name" # 容器名
  2. -d # 后台方式运行
  3. -it # 使用交互方式运行 查看容器内容
  4. -p # 指定容器端口
  5. -P # 随机指定端口

例如,启动并进入容器:

  1. [root@192 ~]# docker run -it centos /bin/bash
  2. [root@081da4d71b9f /]# ls
  3. bin dev etc home lib lib64 lost+found media mnt opt proc root run sbin srv sys tmp usr var
  4. [root@081da4d71b9f /]#

3. 退出容器

exit

例如:

  1. [root@192 ~]# docker run -it centos /bin/bash
  2. [root@000361735e96 /]# ls
  3. bin dev etc home lib lib64 lost+found media mnt opt proc root run sbin srv sys tmp usr var
  4. [root@000361735e96 /]# exit
  5. exit
  6. [root@192 ~]#

4. 列出所有运行的容器

docker ps [参数选项]

参数选项:

  1. -a # 列出历史运行的容器
  2. -n= # 显示最近创建的容器
  3. -q # 显示容器编号

例如:

  1. [root@192 ~]# docker ps -a
  2. CONTAINER ID IMAGE COMMAND CREATED STATUS PORTS NAMES
  3. 000361735e96 centos "/bin/bash" About a minute ago Exited (0) About a minute ago determined_swartz
  4. e6c3827354c7 mysql "docker-entrypoint.s…" 2 minutes ago Exited (1) 2 minutes ago confident_cerf
  5. 081da4d71b9f centos "/bin/bash" 3 minutes ago Exited (0) 2 minutes ago recursing_williams
  6. 4faad9eeee5d centos "/bin/bash" 25 hours ago Exited (0) 23 hours ago epic_mclaren
  7. b6cd9f523eff centos "/bin/bash" 25 hours ago Exited (0) 25 hours ago blissful_lalande
  8. 129ae722b6a4 centos "/bin/bash" 25 hours ago Exited (0) 23 hours ago great_bhabha
  9. 046741dd1f06 centos "/bin/bash" 25 hours ago Exited (0) 25 hours ago inspiring_burnell
  10. 36334e32c2b6 centos "/bin/bash" 25 hours ago Exited (0) 25 hours ago adoring_moore
  11. 540acab799ad d1165f221234 "/hello" 9 days ago Exited (0) 9 days ago eager_noether
  12. 072d7504621d d1165f221234 "/hello" 9 days ago Exited (0) 9 days ago intelligent_antonelli
  13. [root@192 ~]#

5. 容器退出时不停止

按键操作命令:

Ctrl + P + Q

例如:

  1. [root@192 ~]# docker run -it centos
  2. [root@e1a1ad252475 /]# [root@192 ~]#
  3. [root@192 ~]# docker ps
  4. CONTAINER ID IMAGE COMMAND CREATED STATUS PORTS NAMES
  5. e1a1ad252475 centos "/bin/bash" 15 seconds ago Up 14 seconds practical_lamport
  6. [root@192 ~]#

6. 删除容器

  1. docker rm 容器id # 删除指定容器
  2. docker rm -f $(docker ps -aq) # 删除所有容器
  3. docker ps -aq | xargs docker rm # 删除所有容器

例如:

  1. [root@192 ~]# docker rm -f $(docker ps -aq)
  2. e1a1ad252475
  3. 000361735e96
  4. e6c3827354c7
  5. 081da4d71b9f
  6. 4faad9eeee5d
  7. b6cd9f523eff
  8. 129ae722b6a4
  9. 046741dd1f06
  10. 36334e32c2b6
  11. 540acab799ad
  12. 072d7504621d
  13. [root@192 ~]# docker ps
  14. CONTAINER ID IMAGE COMMAND CREATED STATUS PORTS NAMES
  15. [root@192 ~]#

注意:不能直接删除运行中的容器

  1. [root@192 ~]# docker ps
  2. CONTAINER ID IMAGE COMMAND CREATED STATUS PORTS NAMES
  3. e1a1ad252475 centos "/bin/bash" 15 seconds ago Up 14 seconds practical_lamport
  4. [root@192 ~]#
  5. [root@192 ~]#
  6. [root@192 ~]#
  7. [root@192 ~]#
  8. [root@192 ~]# docker rm e1a1ad252475
  9. Error response from daemon: You cannot remove a running container e1a1ad252475df7b76ca74135c2b9a1efc4859b0b253350feba825d767e015e0. Stop the container before attempting removal or force remove
  10. [root@192 ~]#

7. 容器启动和停止

容器启动

  1. docker start 容器id # 容器启动
  2. docker restart 容器id # 容器重启
  3. docker stop 容器id # 容器停止
  4. docker kill 容器id # 杀掉容器

例如:

  1. [root@192 ~]# docker ps -----------------查看容器
  2. CONTAINER ID IMAGE COMMAND CREATED STATUS PORTS NAMES
  3. 3fadac1354b0 centos "/bin/bash" 25 seconds ago Up 24 seconds eloquent_tharp
  4. [root@192 ~]# docker stop 3fadac1354b0 -----------容器停止
  5. 3fadac1354b0
  6. [root@192 ~]# docker ps
  7. CONTAINER ID IMAGE COMMAND CREATED STATUS PORTS NAMES
  8. [root@192 ~]# docker ps -aq
  9. 3fadac1354b0
  10. [root@192 ~]# docker ps -a
  11. CONTAINER ID IMAGE COMMAND CREATED STATUS PORTS NAMES
  12. 3fadac1354b0 centos "/bin/bash" 52 seconds ago Exited (0) 14 seconds ago eloquent_tharp
  13. [root@192 ~]# docker restart 3fadac1354b0 -------------容器重启
  14. 3fadac1354b0
  15. [root@192 ~]# docker ps -a
  16. CONTAINER ID IMAGE COMMAND CREATED STATUS PORTS NAMES
  17. 3fadac1354b0 centos "/bin/bash" About a minute ago Up 2 seconds eloquent_tharp
  18. [root@192 ~]# docker kill 3fadac1354b0 ----------------杀掉容器
  19. 3fadac1354b0
  20. [root@192 ~]# docker ps -a
  21. CONTAINER ID IMAGE COMMAND CREATED STATUS PORTS NAMES
  22. 3fadac1354b0 centos "/bin/bash" About a minute ago Exited (137) 2 seconds ago eloquent_tharp
  23. [root@192 ~]#
声明:本文内容由网友自发贡献,不代表【wpsshop博客】立场,版权归原作者所有,本站不承担相应法律责任。如您发现有侵权的内容,请联系我们。转载请注明出处:https://www.wpsshop.cn/w/羊村懒王/article/detail/511591?site
推荐阅读
相关标签
  

闽ICP备14008679号