- docker 命令: 启动Ubuntu container
docker container run -t ubuntu top
top is a Linux utility that prints the processes on a system and orders them by resource consumption.
Top 命令: 答应系统上的一些进程的信息,并且根据资源消耗进行排序显示。
The -t flag allocates a pseudo-TTY, which you need for the top command to work correctly.
这条命令会启动容器,并且显示容器中的process的相关信息,由于容器隔离的原因,这条命令只能看见一个process的信息,就是top,容器中没有其他的process。
Containers use Linux namespaces to provide isolation of system resources from other containers or the host. The PID namespace provides isolation for process IDs. If you run top while inside the container, you will notice that it shows the processes within the PID namespace of the container, which is much different than what you can see if you ran top on the host.
容器使用Linux名称空间来提供系统资源与其他容器或主机的隔离。 PID名称空间为进程ID提供隔离。 如果在容器内运行top时,您会注意到它显示了容器的PID名称空间中的进程,这与在主机上运行top时所看到的有很大不同。
Even though we are using the Ubuntu image, it is important to note that the container does not have its own kernel. It uses the kernel of the host and the Ubuntu image is used only to provide the file system and tools available on an Ubuntu system.
即使我们使用的是Ubuntu映像,也要注意容器没有自己的内核,这一点很重要。 它使用主机的内核,而Ubuntu映像仅用于提供Ubuntu系统上可用的文件系统和工具。
-
进入运行的容器执行相应的命令
docker container exec ==> docker exec
例子:docker exec -it 9df70f9a0714 /bin/bash ==> 通过 exec 命令进入指定的id的容器,并且执行bash -
docker ps 或者docker container ls ==> 查看正在运行的容器的id
-
ps -ef ==> 查看当前有多少process, 可以在docker exec进入容器之后运行
-
一些概念:下面这些linux的命名空间,为container提供了隔离性,可以使他们安全的在同一个系统上运行。
PID is just one of the Linux namespaces that provides containers with isolation to system resources. Other Linux namespaces include:
MNT: Mount and unmount directories without affecting other namespaces.
NET: Containers have their own network stack.
IPC: Isolated interprocess communication mechanisms such as message queues.
User: Isolated view of users on the system.
UTC: Set hostname and domain name per container.
These namespaces provide the isolation for containers that allow them to run together securely and without conflict with other containers running on the same system.(这些名称空间为容器提供了隔离,使它们可以安全地一起运行,而不会与在同一系统上运行的其他容器发生冲突。)
- docker container run --detach --publish 8080:80 --name nginx nginx
–detach :标志将在后台运行此容器。
–publish :将容器的80端口发布给主机的8080端口,这样在host主机访问8080,就可以访问到容器的80端口,从而可以使用容器的功能。NET名称空间为容器的进程提供了自己的网络堆栈(也就是说容器里面有自己的网络端口啥的)。
–name标志,该标志为容器命名。每个容器都有一个名称。如果您不指定一个,则Docker将为您随机分配一个。指定您自己的名称将使在容器上运行后续命令更加容易,因为您可以引用名称而不是容器的ID。例如,您可以指定docker container inspect nginx而不是docker container inspect 5e1。
怎么知道nginx的端口是80?通过docker hub上关于nginx镜像的介绍文档。https://hub.docker.com/_/nginx
- docker container run --detach --publish 8081:27017 --name mongo mongo:3.4
后面的mongo:3.4可以指定使用镜像的版本
-
docker container inspect [container id] ==> 查看运行的容器的更多相关的信息
-
您无需在主机(Docker以外的主机)上安装任何东西即可运行这些容器, 每个容器镜像都包含其在容器内所需的依赖项,因此您无需直接在主机上安装任何东西。
在同一主机上运行多个容器使我们能够使用单个主机上可用的资源(CPU,内存等)。 这可以为企业节省大量成本。 -
docker container stop [container id或者容器name] ===>停止容器
例子:docker container stop d67 ead af5
- docker system purge
The following command removes any stopped containers, unused volumes and networks, and dangling images。
1万+

被折叠的 条评论
为什么被折叠?



