To execute operations in a container, use the
docker exec command. Sometimes this is called "entering the container" as all commands are executed inside the container.
docker exec -it container_id bash
docker exec -it container_id /bin/sh
And now you have a shell in your running container. For example, list files in a directory and then leave the container:
docker exec container_id ls -la
You can use the
-u flag to enter the container with a specific user, e.g.
docker exec -it -u 1013:1023 container_id ls -la
The uid and gid does not have to exist in the container but the command can result in errors.If you want to launch a container and immediately enter inside in order to check something, you can do
docker run...; docker exec -it $(docker ps -lq) bash
docker ps -lq outputs only the id of the last (the l in
-lq) container started.
(this supposes you have bash as interpreter available in your container, you may have sh or zsh or any other)