UPDATE: EXPLORING!
This command should let you explore a running docker container:
docker exec -it name-of-container bash
The equivalent for this in docker-compose would be:
docker-compose exec web bash
(web is the name-of-service in this case and it has tty by default.)
Once you are inside do:
ls -lsa
or any other bash command like:
cd ..
This command should let you explore a docker image:
docker run --rm -it --entrypoint=/bin/bash name-of-image
once inside do:
ls -lsa
or any other bash command like:
cd ..
The -it
stands for interactive... and tty.
This command should let you inspect a running docker container or image:
docker inspect name-of-container-or-image
You might want to do this and find out if there is any bash
or sh
in there. Look for entrypoint or cmd in the json return.
NOTE: This answer relies on commen tool being present, but if there is no bash
shell or common tools like ls
present you could first add one in a layer if you have access to the Dockerfile
:
example for alpine:
RUN apk add --no-cache bash
Otherwise if you don't have access to the Dockerfile
then just copy the files out of a newly created container and look trough them by doing:
docker create <image> # returns container ID the container is never started.
docker cp <container ID>:<source_path> <destination_path>
docker rm <container ID>
cd <destination_path> && ls -lsah
see docker exec documentation
see docker-compose exec documentation
see docker inspect documentation
see docker create documentation
docker exec <container> bash
. So, you just open a shell inside the container. – dashohoxhadocker exec <container> ls <dir path>
anddocker exec <container> cat <file path>
. For bash however, add the-it
options. – Noam Manosdocker image save image_name > image.tar
as indicated in the response from @Gaurav24. – Jaime Hablutzel