Docker uses the nsenter tool to enter the container

Docker uses the nsenter tool to enter the container

When using Docker containers, it is more convenient to use the nsenter tool. If our system does not have it, we need to install it ourselves

1. First visit this website to find the latest version of the nsenter tool

2. Then download the source code of the nsenter tool to our host

Enter the command:

# wget https://mirrors.edge.kernel.org/pub/linux/utils/util-linux/v2.32/util-linux-2.32.tar.gz

3. Unzip the .tar.gz package

# tar -xzvf util-linux-2.32.tar.gz

4. Enter the directory of util-linux-2.32

# cd util-linux-2.32/

5. Enter the ./configure --without-ncurses command

6. Enter the command make nsenter to compile nsenter

7. Copy nsenter to the /usr/local/bin path

# cp nsenter /usr/local/bin

8. Check the usage of nsenter

# nsenter --help

9. In order to connect to the container, we also need to find the PID of the first process of the container, which can be obtained by the following command

Format:

PID=$(docker inspect --format "{{ .State.Pid}}" <container id>)

By obtaining this PID, you can connect to this container:

Format:

nsenter --target $PID --mount --uts --ipc --net --pid

10. Get the PID of the first process in the container

Enter the command # docker ps to view the running container

Enter the command to view the container

PID of the process of c74e0f07a914# docker inspect -f {{.State.Pid}} c74e0f07a914

10. Get the PID of the process and enter the container

Enter the command

# nsenter --target 21140 --mount --uts --ipc --net --pid

Successfully entered the container, 21140 is the process PID of container c74e0f07a914

The above operation of using the nsenter tool to enter the container in Docker is all the content that the editor shares with you. I hope it can give you a reference. I also hope that you will support 123WORDPRESS.COM.

You may also be interested in:
  • How to use Portainer to build a visual interface for Docker
  • Tutorial on using portainer to connect to remote docker
  • Detailed steps for building Portainer visual interface with Docker
  • Docker and portainer configuration methods under Linux
  • Docker image analysis tool dive principle analysis
  • Installing the ping tool in a container built by Docker
  • Detailed steps to install 64-bit Ubuntu system and Docker tool on Raspberry Pi 3B+
  • How to install and configure the Docker Compose orchestration tool in Docker.v19
  • Installation and usage analysis of Portainer, a visual UI management tool for Docker

<<:  Why MySQL can ignore time zone issues when using timestamp?

>>:  XHTML tags should be used properly

Recommend

Detailed installation and use of virtuoso database under Linux system

I've been researching some things about linke...

Tutorial on how to remotely connect to MySQL database under Linux system

Preface I recently encountered this requirement a...

Detailed explanation of three ways to cut catalina.out logs in tomcat

1. Log4j for log segmentation 1) Prepare three pa...

A brief discussion of the interesting box model of CSS3 box-sizing property

Everyone must know the composition of the box mod...

How to use lazy loading in react to reduce the first screen loading time

Table of contents use Install How to use it in ro...

Explanation of building graph database neo4j in Linux environment

Neo4j (one of the Nosql) is a high-performance gr...

Design reference WordPress website building success case

Each of these 16 sites is worth reading carefully,...

Three ways to communicate between Docker containers

We all know that Docker containers are isolated f...

Ideas and codes for realizing magnifying glass effect in js

This article example shares the specific code of ...

How to set the number of mysql connections (Too many connections)

During the use of mysql, it was found that the nu...

Analysis and description of network configuration files under Ubuntu system

I encountered a strange network problem today. I ...

Summary of several implementations of returning to the top in HTML pages

Recently, I need to make a back-to-top button whe...

5 Ways to Clear or Delete Large File Contents in Linux

Sometimes, while working with files in the Linux ...

Java imports data from excel into mysql

Sometimes in our actual work, we need to import d...