docker四:docker容器命令
容器,是一个在隔离环境里面运行的进程,程序运行结束,进程结束,容器结束。
1.创建并运行一个容器:
# docker run -d -p 80:80 nginx:latest
2.查看所有的容器命令:docker container
[root@localhost ~]# docker container Usage: docker container COMMAND Manage containers Commands: attach Attach local standard input, output, and error streams 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 to files or directories 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 Run 'docker container COMMAND --help' for more information on a command.
3.分配交互式的终端,即进入一个容器
# docker run --it --name centosServer1 centos:6.9 /bin/bash
- -it 分配 交互式的终端
- --name 指定容器的名字
- /bin/sh 进入容器要执行的命令,如果没有指定,就执行默认的初始命令。即进入容器后执行的命令,如果换成ps -ef命令,进入容器后执行这条命令然后马上就退出容器并销毁容器
4.查看正在运行的容器:
docker ps
docker container ls
5.查看所有的容器,包括未运行的:
docker ps -a
docker container ls -a
显示完整的容器信息的时侯,要加参数 --no-trunc
6.停止容器
docker container stop 容器id或名字
7.强制杀死容器
docker container kill 容器id或名字
8.删除容器
docker container rm 容器id或名字
docker rm 容器id或名字
8.进入容器,目的:调试、排错
进入容器:
方式一:docker attach 容器id或名字,不推荐这种方式
方式二:这种方式进入容器,会分配一个新的终端tty
docker exec -it 容器的id或名字 要执行的命令(如/bin/bash)
退出容器:ctr+p,ctr+q
注意:
docker容器内的第一个进程必须一直处于前台运行状态,否则这个容器就会处于退出状态!
posted on 2019-08-04 21:58 myworldworld 阅读(173) 评论(0) 收藏 举报