Docker: Four Useful Docker Commands that Could Boost Your Workflow

July 27, 2021

Today, we want to briefly introduce four docker commands that might help your workflow.

  1. Access the Terminal of a Running Container
    A lot of times, you would want to investigate if the container has the right files in it and the way to probe it is to access the terminal of this running container. Then you can use all the terminal commands that you are familiar to check the container.
$ docker exec -it container_name /bin/bash

If you don’t have the container running and you want to access the terminal after it starts to run, then you should use the following command.

$ docker run -it container_name bash

2. Clean Everything Stopped
If you want to clean everything including the images, containers, networks, cache and volumes, you can use the following command. This helps you to rebuild everything from scratch, if you choose to.

$ docker system prune -a --volumes

3. Copy Files between Host and Container
Copy a file from a host to a running container:

$ docker cp /file_path/file_name container_name:/file_path/file_name

Copy a file from a container to a host:

$ docker cp container_name:/file_path/file_name /file_path/file_name

4. Fetch Logs of a Running Container
This command helps you to check the logs of a running container, which will help you to further debug your container if necessary.

$ docker logs container_name

Thank you!