Docker troubleshooting tips and tricks

Docker troubleshooting tips and tricks

Docker is a great way to run web apps on your server. However there are times when problems can arise and figuring out where the trouble is can be tricky. Here are a few commands that can help you figure out the cause of the trouble.

docker-compose up without the -d gives you an interactive look as your container loads. Depending on the container, the information provided can be very useful in tracking down the problem.

docker-compose up -d --build starts docker and builds image docker-compose up -d starts docker image.

docker container ls lists all the active containers and shows each container id. docker container ls -a shows containers that are not running also.

docker exec -it docker_container_id sh allows you to sh into a container so you can run commands inside of the container. Also you don't just need to sh, you can run commands on your database, etc. docker exec -i docker_container_id /usr/bin/psql -h db -U postgres -d my_db

docker container ls --format "table {{.ID}}\t{{.Names}}\t{{.Ports}}" -a Find all of the ports in use on your docker containers with their internal and external network ports. Very useful for troubleshooting your network connections.

docker network ls shows your network names and ids.

docker network rm network_name removes a network.

docker network create network_name creates a network.

docker container rm docker_container_id removes a container.

docker-compose down --volumes sometimes you want to reinstall a container and get rid of any data stored locally in volumes. This command also eliminates the stored volume data. Very useful when you need to redo a container from scratch.

docker container prune remove all stopped containers.

docker volume prune remove all stopped volumes.

docker network prune remove all stopped networks.

docker inspect container_name get lots of interesting info about a container.

docker stop container_id stops current container also docker kill container_id .

docker-compose up --build --force-recreate --no-deps force a container to rebuild from scratch. Sometimes the containers do not properly rebuild when they are changed.