Friday, 8 February 2019

Useful docker commands


# Go inside contianer
docker exec -it <mycontainer> bash

# Inspect network id of container
docker inspect -f '{{.State.Pid}}' <container_id>

# Show newtwork stats and port
sudo nsenter -t <network_id -n netstat

nsenter -t <network_id> -n netstat -na | grep :5671


-------------------------
# Show docker network
docker network ls
docker network inspect <network_name>
(Docker compose file either takes one internal ip for all services or seperate ip for each service, inspect network)

# remote ping internal_ip to see if docker container is reachable
# curl internal_ip:port see if it is working
# rabbitmq uses 15672 as default port for mangement tool ui
# see if port is open on remote
nc -zv 127.0.0.1 5671
# see if port is open on container
nc -zv <docker_container_internal_ip> 5671

// Go inside docker contianer
docker exec -it <container_id> bash
// Check port
ss -an | grep :5671


---------------open new port on running container (DOCKER NOT DOCKER COMPOSE)-------------------
docker commit containerID newImageName:tag (shared volume)

// Make new image
docker commit <container_id> jx_rabbitmq_backup:1.0

docker container stop <container_id>

docker container ls -a (ensure container stoppped)

docker container ls (currently running container)

docker run -d -p 5671:5671 -p 15672:15672 jx_rabbitmq_backup:1.0

-------------------------(This won't work for container using docker compose, docker network ls , the brdige network created by yml still points to old container)
// See if this internal port can be accessed from remote
curl 172.19.0.2:15672
// update docker compose yml file to open external port

// update container (--no-deps does not start dependency)

docker-compose -f docker-compose.prod.yml up --build --no-deps -d SERVICE_NAME_IN_YML


docker-compose -f docker-compose.yml up --build --no-deps -d rabbitmq





debug
-------
// check docker compose.yml file for service_you_lookfor, ports: '5671:5671', hostname
// find container ID
docker container ls

// find container internal ip
docker inspect <container_id>

// Check if port is open on remote
nc -zv 127.0.0.1 5671
nc -zv <contianer_ip> 5671
// ping hostname
ping hostname

// Go inside docker contianer
docker exec -it <container_id> bash
// Check port
ss -an | grep :5671
// Run command to ensure its ok

// If still doesnt work, port needs ssl authentication, so 5671 is not http/https, need a client to access instead of browser


----
login to postgres
// find container ID
docker container ls
// find container internal ip
docker inspect <container_id>
// Go inside docker contianer
docker exec -it <container_id> bash
// in .env file where docker compose file is find db name credential
// psql -h <container_IP> -U <user_name> <d_b>
// \dt to show all tables
// \q to quit
// SELECT * FROM table 1 ; to query




 rabbitmq-plugins enable rabbitmq_management


No comments:

Post a Comment