用nsenter进入容器

操作容器的命令以“docker”开头,并在root用户下操作

  1. docker ps :显示正在运行的容器,看有没有正在运行的容器

    [root@localhost zh]# docker ps
    CONTAINER ID        IMAGE               COMMAND             CREATED             STATUS              PORTS               NAMES
    ff4c2116a0e6        centos              "/bin/bash"         About an hour ago   Up 29 minutes                           compassionate_easley
    
  2. docker ps :docker ps -a :显示所有的容器

    [root@localhost zh]# docker ps -a
    CONTAINER ID        IMAGE                     COMMAND             CREATED             STATUS                           PORTS               NAMES
    0ecf337a43e7        docker.io/centos:latest   "/bin/bash"         About an hour ago   Exited (127) About an hour ago                       affectionate_stonebraker
    0c870bed1077        docker.io/centos:latest   "/bin/bash"         About an hour ago   Exited (0) About an hour ago                         stoic_lamarr
    ff4c2116a0e6        centos                    "/bin/bash"         About an hour ago   Up 30 minutes                                        compassionate_easley
    
  3. docker inspect 容器id:查看容器的详细信息

  4. docker start 容器id:启动容器,使其状态变为running

    [root@localhost zh]# docker start ff4c2116a0e6  
    ff4c2116a0e6
    
  5. 容器启动起来后,用docker inspect -f {{.State.Pid}} ff4c2116a0e6
    查看该容器的第一个进程pid

    [root@localhost zh]# docker inspect -f {{.State.Pid}} ff4c2116a0e6
    10456
    
  6. nsenter --target pid --type(net、ipc、PID等命名空间),此条命令执行后就进入了命名空间

  7. exit:退出

你可能感兴趣的:(用nsenter进入容器)