I'm getting started working with Docker. I'm using the WordPress base image and docker-compose.
I'm trying to ssh into one of the containers to inspect the files/directories that were created during the initial build. I tried to run docker-compose run containername ls -la
, but that didn't do anything. Even if it did, I'd rather have a console where I can traverse the directory structure, rather than run a single command. What is the right way to do this with Docker?
If you're here looking for a Docker Compose-specific answer like I was, it provides an easy way in without having to look up the generated container ID.
docker-compose exec
takes the name of the service as per yourdocker-compose.yml
file.So to get a Bash shell for your 'web' service, you can do:
To inspect files, run
docker run -it <image> /bin/bash
to get an interactive terminal. The list of images can be obtained bydocker images
. In contrary todocker exec
this solution works also in case when an image doesn't start (or quits immediately after running).In my case, for some reasons I need to check all network involved information in each container. So the following commands must be valid in container...
I checked through all these answers, no valid for me. I’ve searched information in other websites. I won’t add a super link here, since it’s not written in English. So I just put up this post with summary solution for people who has the same requirement as me.
Say you have one running container named light-test. Follow the steps below.
docker inspect light-test -f {{.NetworkSettings.SandboxKey}}
. This command will get reply like/var/run/docker/netns/xxxx
.ln -s /var/run/docker/netns/xxxx /var/run/netns/xxxx
. The directory may not exist, domkdir /var/run/netns
first.ip netns exec xxxx ip addr show
to explore network world in container.PS.
xxxx
is always a same value got through the first command. And of course, any other commands are valid, i.e.ip netns exec xxxx netstat -antp|grep 8080
.