Table of Contents
- Delete every Docker containers
- Open shell in running container
Figure 1. A very small tip for you!
The sole purpose of this post is to help me to return here time to time if I forget some of the commands.If this would be useful for anyone - praise me on twitter - http://twitter.com/gamussa.
Let’s start with a small but important thing - how to erase everything Docker and start clean.
Delete every Docker containers
|NOTE:| Don’t do this if you’re on the plane. Downloading new images using the airline’s wifi will be the pain. Proceed with caution. You have been warned. |
How many time you have found yourself running out of space in your laptop, and you don’t know who’s eating all the space.Usual suspects here are maven or gradle directory jar’s directory and Docker images directory.
❯ du -sh ~/.m2 2.4G /Users/viktor/.m2 (1) ❯ du -sh ~/.gradle 2.8G /Users/viktor/.gradle (2) ❯ du -sh ~/Library/Containers/com.docker.docker/Data/com.docker.driver.amd64-linux/Docker.raw 8.1G /Users/viktor/Library/Containers/com.docker.docker/Data/com.docker.driver.amd64-linux/Docker.raw
| 1 | Should I nuke it? |
| 2 | I definitely use Gradle more |
Must be run first because images are attached to containers
docker rm -f $(docker ps -a -q)
Delete every Docker image
docker rmi -f $(docker images -q)
Open shell in running container
If I have a container that already running I can use
docker exec command to connect to it!
First, get the name of the existing container using
docker exec -it <container name> /bin/bash to get a bash shell in the container
docker exec -it <container name> <command> to execute whatever command you specify in the container.
Extra curriculum material: How to do the same in case of Docker Compose?
docker-compose run <container_name_in_yml_file> <command>.
E.g. to get a shell into your Kafka container, you might run
docker-compose run kafka1 /bin/bash
To run a series of commands, you must wrap them in a single command using a shell
docker-compose run <name in yml> sh -c '<command 1> && <command 2> && <command 3>'
docker run command accepts command-line options to specify volume mounts, environment variables, the working directory, and more.
Top comments (0)