docker 的容器入门

Linux Namespace

LXC所实现的隔离性主要是来自kernel的namespace, 其中pid, net, ipc, mnt, uts 等namespace将container的进程, 网络, 消息, 文件系统和hostname 隔离开。

Control Groups

cgroups 实现了对资源的配额和度量。 cgroups 的使用非常简单,提供类似文件的接口,在 /cgroup目录下新建一个文件夹即可新建一个group,在此文件夹中新建task文件,并将pid写入该文件,即可实现对该进程的资源控制。具体的资源配置选项可以在该文件夹中新建子 subsystem ,{子系统前缀}.{资源项} 是典型的配置方法。
安装docker
[root@localhost ~]# yum -y install epel-release
[root@localhost ~]# yum -y install docker
[root@localhost ~]# systemctl start docker
[root@localhost ~]# docker images   查看存在的镜像
REPOSITORY          TAG                 IMAGE ID            CREATED             SIZE
[root@localhost ~]# docker pull tomcat  下载镜像
Using default tag: latest
Trying to pull repository docker.io/library/tomcat ... 
latest: Pulling from docker.io/library/tomcat
54f7e8ac135a: Pull complete 
d6341e30912f: Pull complete 
087a57faf949: Pull complete 
95065f220961: Pull complete 
0887630ce576: Pull complete 
c375d1959fab: Pull complete 
e00a5e6055cc: Pull complete 
8319f5fb56cf: Pull complete 
258c74eb25ab: Pull complete 
6eb86d11d371: Pull complete 
adb5a4a6adf5: Pull complete 
4685b434f297: Pull complete 
Digest: sha256:e394c2f94eee344300e68d7183f3f19d272316f9691b280ac0e3911ea610e590
Status: Downloaded newer image for docker.io/tomcat:latest
[root@localhost ~]# docker images 
REPOSITORY          TAG                 IMAGE ID            CREATED             SIZE
docker.io/tomcat    latest              78b258e36eed        13 days ago         463 MB
[root@localhost ~]# docker run -it -d -p 8888:8080 tomcat:latest 后台启动容器将容器的8080与本机的8888端口进行绑定 d588baa6a123a47913a112a5c3ee3f52f0a9f2c2c412ec1a46a527f32222ab6a

前端访问http://192.168.10.31:8888/

查看运行容器

[root@localhost ~]# ss -lntp
State       Recv-Q Send-Q                                                  Local Address:Port                                                                 Peer Address:Port              
LISTEN      0      128                                                                 *:22                                                                              *:*                   
users:(("sshd",pid=1000,fd=3))LISTEN      0      100                                                         127.0.0.1:25                                                                              *:*                   
users:(("master",pid=1159,fd=13))LISTEN      0      128                                                                :::22                                                                             :::*                   
users:(("sshd",pid=1000,fd=4))LISTEN      0      128                                                                :::8888                                                                           :::*                   
users:(("docker-proxy-cu",pid=2762,fd=4))LISTEN      0      100                                                               ::1:25                                                                             :::*                   
users:(("master",pid=1159,fd=14))
[root@localhost ~]# docker ps CONTAINER ID IMAGE COMMAND CREATED STATUS PORTS NAMES 967a88f8ea47 tomcat:latest "catalina.sh run" 3 minutes ago Up 3 minutes 0.0.0.0:8888->8080/tcp wonderful_swanson

停止容器停止

[root@localhost ~]# docker stop 967a88f8ea47 停止容器
967a88f8ea47
[root@localhost ~]# docker ps  查看运行的容器
CONTAINER ID        IMAGE               COMMAND             CREATED             STATUS              PORTS               NAMES
[root@localhost ~]# docker ps -a  查看所有容器
CONTAINER ID        IMAGE               COMMAND             CREATED             STATUS                       PORTS               NAMES
967a88f8ea47        tomcat:latest       "catalina.sh run"   7 minutes ago       Exited (143) 7 seconds ago                       wonderful_swanson

  

 

猜你喜欢

转载自www.cnblogs.com/rdchenxi/p/10047901.html