Linux & Docker Commands Reference & Troubleshooting

We’ve published these commands for our developers for reference purposes. They are publicly visible as it might be helpful for other developers as well:

Docker

#stop all containers: docker stop $(docker ps -a -q)

Restart docker service

sudo systemctl restart docker.service Recreate all container docker-compose up --build --force-recreate --no-deps #stop all containers by force docker kill $(docker ps -q) #remove all containers docker rm $(docker ps -a -q) #remove all docker images docker rmi $(docker images -q) #purge the rest docker system prune --all --force --volumes #Find IP of a container docker inspect -f '{{range.NetworkSettings.Networks}}{{.IPAddress}}{{end}}' [container_name] #Show docker logs docker-compose logs #Show docker process docker-compose ps Execute mysqldump in container docker exec [container_name] sh -c 'exec mysqldump --all-databases -uroot -p[password]' > /home/user/all-databases.sql Error response: Could not kill running container runc did not terminate successfully: container_linux.go:392: init process caused “permission denied” This can happen if apparmor prevents stopping the docker container. One solution is to uninstall apparmor and restarting the docker service: sudo apt-get purge --auto-remove apparmor sudo service docker restart docker system prune --all --volumes sudo systemctl restart docker sudo systemctl daemon-reload Error starting userland proxy: listen tcp 172.200.0.1:443: bind: address already in use Find PID and kill it: sudo netstat -nlpt |grep 3306 sudo kill [pid]

Network

Number of open connections per ip netstat -ntu | awk ‘{print $5}’ | cut -d: -f1 | sort | uniq -c | sort -n Show all connected ip addresses to a certain port netstat -an |grep 443 netstat -an |grep 80 Count connections per IP netstat -an | grep 80 | wc -l netstat -an | grep 443 | wc -l

Firewall iptables

Firewall Block IP Adresssudo iptables -A INPUT -s [IP ADDRESS] -j DROP Allow access from a specific IP addresssudo iptables -A INPUT -s 91.52.78.249 -p tcp –destination-port 3306 -j ACCEPT Unban IP addresses blocked by fail2ban iptables -D [chain] [line] z.B. iptables -D f2b-wordpress-hard 1 Firewall Rules See: https://www.digitalocean.com/community/tutorials/how-to-set-up-a-firewall-with-ufw-on-ubuntu-18-04

  • sudo ufw default deny incoming
  • sudo ufw default allow outgoing
  • sudo ufw allow ssh
  • sudo ufw allow 1000
  • sudo ufw allow http
  • sudo ufw allow 443
  • sudo ufw allow from 91.52.78.249 to any port 3306 (Local IP address)
  • sudo ufw allow from 52.45.200.92 to any port 3306 (Amazon DBS)
  • sudo ufw deny from 157.245.247.135

MySQL

Change MySQL password authentication module tomysql_native_password. Needed for upgrading from 7.X to mysql 8.x ALTER USER ‘user’@’localhost’ IDENTIFIED WITH mysql_native_password BY ‘password1’;

Debug xDebug:-)

If your code editor does not connect to xDebug create a file test.php in your app folder with some code and add a breakpoint to it. Then run the command below to test it:

PHP_IDE_CONFIG="serverName=tests" php -dxdebug.remote_autostart=1 -dxdebug.remote_enable=1 -dxdebug.default_enable=1 -dxdebug.remote_connect_back=1 -dxdebug.remote_port=9001 -dxdebug.idekey=PHPSTORM -dxdebug.remote_host=172.200.0.1 test.php

Login reloads the login prompt

If you try to login to KDE and the login form reloads after entering correct credentials try the commands below:

systemctl stop gdm.service
systemctl restart gdm.service
sudo dpkg-reconfigure gdm3
reboot
Rene Hermenau

Author: Rene Hermenau

About the author: René Hermenau is the founder of WP STAGING. He works on WordPress backups, staging, migrations, database handling, and safe deployment workflows.