• docker学习


    yum install -y docker

    nsenter belongs to util-linux
    
    
    docker run --name mydocker
    
     docker inspect -f "{{ .State.Pid  }}" mydocker
    
    nsenter -t 14301 -m -u -i -n -p
    
    
    
    [root@node1 ~]# ./docker.sh mydocker
    root@ad347571682b:/# pwd
    /
    root@ad347571682b:/# exit
    logout
    [root@node1 ~]# docker ps
    CONTAINER ID        IMAGE               COMMAND             CREATED             STATUS              PORTS               NAMES
    ad347571682b        docker.io/nginx     "/bin/bash"         25 minutes ago      Up 15 minutes       80/tcp, 443/tcp     mydocker
    [root@node1 ~]# cat docker.sh
    #!/bin/bash
    
    # Use nsenter to access docker
    
    docker_in(){
        NAME_ID=$1
        PID=$(docker inspect -f "{{ .State.Pid  }}" $NAME_ID)
        nsenter -t $PID -m -u -i -n -p
    }
    
    docker_in $1
    
    
    
    [root@node1 ~]# docker exec mydocker ps
      PID TTY          TIME CMD
      165 ?        00:00:00 ps
    
    
    [root@node1 ~]# docker exec mydocker ps aux
    USER       PID %CPU %MEM    VSZ   RSS TTY      STAT START   TIME COMMAND
    root         1  0.0  0.0  20236  1908 ?        Ss+  06:54   0:00 /bin/bash
    root       173  0.0  0.0  17492  1132 ?        Rs   07:12   0:00 ps aux
    [root@node1 ~]# docker exec -it mydocker /bin/bash
    root@ad347571682b:/# exit
    exit
    [root@node1 ~]# docker ps
    CONTAINER ID        IMAGE               COMMAND             CREATED             STATUS              PORTS               NAMES
    ad347571682b        docker.io/nginx     "/bin/bash"         28 minutes ago      Up 18 minutes       80/tcp, 443/tcp     mydocker
    [root@node1 ~]#
    
    
    docker exec and docker.sh 都能进入容器并且exit不会关闭容器
    
    
        rm        Remove one or more containers
        rmi       Remove one or more images
    
    [root@node1 ~]# docker run --rm centos date
    
    网络随机映射,-P随机映射,-p指定映射,多个-p可以多端口映射
    
    docker run -d -p 192.168.3.3:81:80 --name mynginx nginx
    
    [root@node1 ~]# docker port mynginx
    80/tcp -> 192.168.3.3:81
    
    docker ps 也能看到多个端口
    
    
    [root@node1 /]# docker run -d --name nginx-volume-test1 -v /data nginx
    
    
    docker run -d --name nginx-volume-test2 -v /data/docker:/data nginx
    
     共享容器
    [root@node1 /data/docker]# docker ps
    CONTAINER ID        IMAGE               COMMAND                  CREATED             STATUS              PORTS               NAMES
    0e4589cafb94        nginx               "nginx -g 'daemon off"   12 minutes ago      Up 12 minutes       80/tcp, 443/tcp     nginx-volume-test2
    6369516a1912        nginx               "nginx -g 'daemon off"   15 minutes ago      Up 15 minutes       80/tcp, 443/tcp     nginx-volume-test1
    [root@node1 /data/docker]# docker run -it --name valume-test3 --volumes-from nginx-volume-test2 centos /bin/bash
    
    
    [root@node1 ~]# docker run  -it --name nfsc --rm --volumes-from nfs centos /bin/bash
    
    
    docker run --name mynginx -it centos
    进容器,rpm -ivh epel
    yum install -y nginx
    /etc/nginx/nginx.conf
    daemon off
    
    [root@node1 ~]# docker commit -m "mynginx" 71d04e9e2b55 wis/nginx:v1
    sha256:0e0458ff3f0d754dcbe3edb1f94e0565d728228103860c71511acd84b367d467
    [root@node1 ~]# docker images
    REPOSITORY          TAG                 IMAGE ID            CREATED             SIZE
    wis/nginx           v1                  0e0458ff3f0d        5 seconds ago       349.8 MB
    
    [root@node1 ~]# docker run -d -p81:80 --name nginxv1 wis/nginx:v1 nginx
    
    
    
    
    [root@node1 /opt/dockerfile/nginx]# cat Dockerfile
    # This Dockerfile
    
    # Base image
    FROM centos
    
    # Maintainer
    MAINTAINER Wis.Wang xxx@qq.com
    
    # Commands
    RUN rpm -ivh http://mirrors.aliyun.com/epel/epel-release-latest-7.noarch.rpm
    RUN yum install -y nginx && yum clean all
    RUN echo "daemon off;" >> /etc/nginx/nginx.conf
    ADD index.html /usr/share/nginx/html/index.html
    EXPOSE 80
    CMD ["nginx"]
    
    [root@node1 /opt/dockerfile/nginx]# pwd
    /opt/dockerfile/nginx
    [root@node1 /opt/dockerfile/nginx]# cat index.html
    DengGOD
    
    [root@node1 /opt/dockerfile/nginx]# docker build -t mynginx:v2 .
    
    docker run --rm --name mynginxv3  -p 82:80 mynginx:v2
    
    centos-ssh
    
    app
    
    requirements.txt
    
    python-demo.ini
    
    
    [root@node1 ~/docker]# tree .
    .
    |-- app
    |   |-- shop-api
    |   |   |-- Dockerfile
    |   |   |-- app-supervisor.ini
    |   |   |-- app.py
    |   |   |-- requirements.txt
    |   |   `-- supervisord.conf
    |   `-- xxx-api
    |-- runtime
    |   |-- java
    |   |-- php
    |   |-- python
    |   `-- python-ssh
    |       `-- Dockerfile
    `-- system
        |-- Dockerfile
        |-- a
        `-- epel.repo
    
    
    
    
    
    https://github.com/vmware/admiral/blob/master/auth/src/main/java/com/vmware/admiral/auth/AuthInitialBootService.java
  • 相关阅读:
    聊天的时间显示
    Android下Affinities和Task
    android Notification 的使用
    Android Notification使用及取消
    类似微信发图片的样式
    Delphi---TServerSocket和TClientSocket发送和接收大数据包
    使用拷贝文件测试(BufferedInputStream,FileInputStream)
    android-getTextSize返回值是以像素(px)为单位的,setTextSize()以sp为单位
    怎样成为PHP 方向的一个合格的架构师
    mac 查看某个文件夹下所有隐藏文件(夹)的大小
  • 原文地址:https://www.cnblogs.com/WisWang/p/6537346.html
Copyright © 2020-2023  润新知