Docker Tips & Tricks

These are some useful random tricks I’ve learned about Docker over the years.

Getting Shell Access to a Running Container

docker exec -it containername /bin/bash

Remove All Running Containers

This command works by removing all running containers with force. The command “docker ps -aq” returns all running containers and only displays the container ID.

docker rm -f $(docker ps -aq)

Copying Files Into the Container

https://docs.docker.com/engine/reference/commandline/cp/

Get the IP Address of a Running Container

The Docker Inspect command allows querying very specific information such as the IP address from the running container.

docker inspect -f "{{ .NetworkSettings.Networks.nat.IPAddress }}" nugetserver

Querying Images Using HTTPie

This command will query the Microsoft Container Registry (MCR) for a list of all available Docker images for SQL Server.

http --follow https://mcr.microsoft.com/v2/mssql/server/tags/list