In addition to Weibo, there is also WeChat
Please pay attention
WeChat public account
Shulou
2025-02-28 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Servers >
Share
Shulou(Shulou.com)06/01 Report--
This article is to share with you about how to use nsenter in Ubuntu to enter the Docker container. The editor thinks it is very practical, so I share it with you. I hope you can get something after reading this article.
After the Docker container is running, how to enter the container for operation? At first I used SSH. If you start only one container, you can handle it with SSH. You only need to map port 22 of the container to a port on the local machine. When I started five containers, each container is not configured with SSH Server by default, so it is troublesome to install and configure SSHD and map the container SSH port.
I have found that many Docker images do not have SSHD services installed. Is there any other way to enter the Docker container?
After browsing through the Docker documents, I couldn't find the answer. You still have to turn to the omnipotent Google. The almighty Google told me to use nsenter.
In most Linux distributions, the util-linux package contains nsenter. If not, you need to install it.
Cd / tmpcurl https://www.kernel.org/pub/linux/utils/util-linux/v2.24/util-linux-2.24.tar.gz\ | tar-zxf-cd util-linux-2.24./configure-- without-ncursesmake nsentercp nsenter / usr/local/bin
Using the shell script docker-enter, save the following code as docker-enter, chomod + x docker-enter
#! / bin/sh if [- e $(dirname "$0") / nsenter]; then # with boot2docker, nsenter is not in the PATH but it is in the same folder NSENTER=$ (dirname "$0") / nsenter else NSENTER=nsenter fi if [- z "$1"]; then echo "Usage: `basename" $0 "`CONTAINER [COMMAND [ARG].]" Echo "" echo "Enters the Docker CONTAINER and executes the specified COMMAND." Echo "If COMMAND is not specified, runs an interactive shell in CONTAINER." Else PID=$ (docker inspect-- format "{{.State.Pid}" $1 ") if [- z" $PID "]; then exit 1 fi shift OPTS="-- target $PID-- mount-- uts-- ipc-- net-- pid-"if [- z" $1 "]; then # No command given. # Use su to clear all host environment variables except for TERM, # initialize the environment variables HOME, SHELL, USER, LOGNAME, PATH, # and start a login shell. "$NSENTER" $OPTS su-root else # Use env to clear all host environment variables. "$NSENTER" $OPTS env-ignore-environment-"$@" fi fi
Run docker-enter to enter the specified container
The above is how to use nsenter in Ubuntu to enter the Docker container. The editor believes that there are some knowledge points that we may see or use in our daily work. I hope you can learn more from this article. For more details, please follow the industry information channel.
Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.
Views: 0
*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.
Continue with the installation of the previous hadoop.First, install zookooper1. Decompress zookoope
"Every 5-10 years, there's a rare product, a really special, very unusual product that's the most un
© 2024 shulou.com SLNews company. All rights reserved.