How do I get to the container after the Docker container is running? At first I was using SSH. If you only start a container and use SSH to handle it, you only need to map the container's 22 port to one of the local ports. When I started the five containers, each container by default is not configured SSH server, installation configuration sshd, map container ssh port, it is really troublesome.
I find that many Docker images are not installed with sshd service, is there any other way to get into the Docker container?
Browsing the Docker documentation, I didn't find the answer. Still want to turn to the omnipotent Google, almighty Google told me to use Nsenter bar.
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 shell script Docker-enter, save the following code as Docker-enter,chomod +x docker-enter
#!/bin/sh if [-E $ (dirname "$")/nsenter]; Then # with Boot2docker, Nsenter was not in the PATH but it was in the same folder nsenter=$ (dirname "$")/nsenter El Se nsenter=nsenter fi if [-Z "$"]; Then echo "Usage: ' basename" $ "' CONTAINER [COMMAND [ARG] ...]" echo "echo" enters the Docker CONTAINER and executes the specified COMMAND. " echo "If COMMAND is not specified, runs a interactive shell in CONTAINER." Else pid=$ (Docker inspect--format "{{. State.pid}} "" $ ") if [-Z ' $PID]; Then exit 1 fi shift opts= "--target $PID--mount--uts--ipc--net--pid--" If [-Z "$"]; 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--"[EmaiL protected] "fi fi
Run docker-enter <container id>
so that it goes into the specified container
For more detailed use of nsenter see here Https://github.com/jpetazzo/nsenter
Using Nsenter to enter the Docker container