Connecting to Docker Containers
I have been installing and exposing SSH on most of the containers I have deployed, which I know is wrong.
As I have been trying to do things in a more “devops” way I decided to do a little reading on how I can enter and leave running containers on my CentOS 7 instance without having to expose SSH or configure users.
This is when I came across nsenter & docker-enter. As you can see from the following instructions and terminal session installing nsenter and then using docker-enter to connect to a running container is a breeze;
docker run — rm jpetazzo/nsenter cat /nsenter > /tmp/nsentermv /tmp/nsenter /usr/local/bin/chmod 755 /usr/local/bin/nsenternsenter -Vnsenter — helpcurl -o /usr/local/bin/docker-enter https://raw.githubusercontent.com/jpetazzo/nsenter/master/docker-enterchmod 755 /usr/local/bin/docker-enter
Now you have installed nsenter and docker-enter you need to lauch a container to conect to;
docker run -d -p 3306:3306 — name testing russmckendrick/mariadbdocker logs testingdocker-enter testing # Enters the container, type exit to exit o_Odocker-enter testing ls -lha /var/lib/mysql/ # Lists the contents of /var/lib/mysql/docker-enter testing ps -aux # Shows the running processes
You can view this process in the embedded terminal session below or on my asciinema profile
Related Posts

Shopping for Containers
Explore the Docker Store, your one-stop marketplace for Docker-related content. From Docker EE to plugins and containers, find both free and paid offerings.

Trying out Elastic Beats
Explore Elastic Beats for data shipping in DevOps. Learn to set up and configure Metricbeat on Docker Swarm for system and Docker metrics analysis.

Portainer, a UI for Docker
Discover Portainer: Simplify Docker management (150k+ pulls). Open-source tool streamlines container deployment, management & monitoring for devs & DevOps.