Networking
- List network setup: docker
network ls
- List:
docker network inspect -f '{{range .IPAM.Config}}{{.Subnet}}{{end}}' [networkid]
- List IPs of all containers.
docker network inspect -f '{{json .Containers}}' [networkid] | jq '.[] | .Name + ":" + .IPv4Address'
- View host setup:
docker exec [nameofnode] cat /etc/hosts
- Running a named container: docker run -name api1 -p 8080:80 gcp-api
Installing ping in the container: https://stackoverflow.com/questions/39901311/docker-ubuntu-bash-ping-command-not-found
Setting up a network:
https://www.digitalocean.com/community/questions/how-to-ping-docker-container-from-another-container-by-name
Docker networking for Dummies (like me) https://www.freecodecamp.org/news/how-to-get-a-docker-container-ip-address-explained-with-examples/
Classic Setup (web, api, sql)
Setting up the classical environment of having the following 3 components, Web, API, SQL
- Run all as named containers (web1, api1, sql1)
- Create the network:
docker create myNet
- Add the containers to the network:
docker network connect myNet web1
docker network connect myNet
api1
docker network connect myNet
websql1
- Check that the network is as expected: docker network inspect myNetwork
- More: https://www.digitalocean.com/community/questions/how-to-ping-docker-container-from-another-container-by-name
A few extra notes
A note to self. Use remote command bash when the docker attach command hangs: docker exec -it [container-id] bash