I’ve been playing around and modifying some existing Docker containers recently and here’s a couple of commands that I found out I use a lot. There’s a lot of extra flags you can give these little commands and you can peruse the docs for more information on them.
docker ps lets you list all your running containers and their details. A lot of the times you need the container name or ID for various reasons and this allows you to grab that information. Super handy.
Another good command for listing things (images specifically) is docker image ls. This lets you list all of the images.
docker logs [container name] is great for debugging and checking any logs that may occur in your container.
docker exec -it [container name or ID] /bin/bash lets you start a bash session in the container you define. You can use the container name or it’s id (which you handily got from using docker ps. The -it is saying to keep STDIN open even if not attached and to allocate a pseudo-TTY. Within this you can go to town making changes. Keep in mind the container is stateless, so you’re not going to have anything saved if you restart the container. Use exit to quit and return to your main terminal.
docker kill [container name or ID] will kill the container and you’ll no longer see it in your list-o-docker-containers when you run docker ps. However to completely remove it, you may need to follow it up with docker rm [container name or ID] if you get an error fussing about already being in use by container X. I’ve found this to be the case for me a lot.
-Rachel
