Basic commands
List docker containers
docker ps
Restart docker container
docker restart <container-name>
Networks
List docker networks
docker network ls
Attach container to network
Example when containers need to communicate on the same network, e.g a proxy manager services needing to communicate on the same network as other containers
docker network connect <network-name> <container-name>
Detach network from container
docker network disconnect <network-name> <container-name>
Gracefully shutdown container with docker compose
docker stop <container-name>
This can be done from within the project /dir if using docker compose:
docker compose down <container-name>
If the network is attached, use network disconnection above.
Remove all containers within the docker-compose.yml file
For e.g associated services
sudo docker compose down --volumes --remove-orphans
Remove docker images
docker images --> list them
docker rmi <image-name>
Gracefully shutdown container w/out docker compose
docker stop <container-name>
docker rm <container-name>
docker network rm <network-name> --> if there's a network
Create shell session in container
sudo docker exec -it <container-name> /bin/bash