Some useful linux and docker commands
By Tri Nguyen onIntro
In this post I would like to list some useful commands for using Docker in Linux.
Dockers
- List all images with their IPs.
docker ps -q | xargs -n 1 docker inspect --format '{{ .Name }} {{range .NetworkSettings.Networks}} {{.IPAddress}}{{end}}' | sed 's#^/##';
- List all files of a volume
docker run -it --rm -v named_volume:/vol busybox ls -l /vol
- Delete all obsolete images, volumes and networks…
docker system prune --volumes
- Start a dummy image to create a network interface with specific IP sub-range.
version: '3.5'
services:
network_default:
image: hello-world:latest
networks:
default:
driver: bridge
ipam:
driver: default
config:
- subnet: 192.168.0.0/16
and then use the network for the image as following
networks:
default:
external:
name: network_default
- Save image to file.
docker save -o ./{filename}.tar {image_name}
The image_name can be get through
docker images
- To install .tar file
docker load -i {filename}.tar
Linux
- List all folders of the first level with size.
du -h --max-depth=1
or
sudo df -h
- Check if port is in use
sudo lsof -i -P -n
or
sudo lsof -i -P -n | grep dotnet
- List all opened ports through firewall
sudo firewall-cmd --list-all
- Update Ubuntu system
sudo apt-get update
sudo apt-get upgrade
sudo apt-get dist-upgrade
sudo apt-get autoremove
sudo reboot
- Show summary info of Ubuntu system.
landscape-sysinfo
- Enable root for SSH.
sudo passwd root
sudo vi /etc/ssh/sshd_config
Set following properties.
PermitRootLogin yes
PasswordAuthentication yes
Restart SSH.
sudo service sshd restart
- Install Certbot and create certificate for a domain.
sudo apt install certbot python3-certbot-nginx
sudo certbot --nginx -d {domain}
- Check if port is accessible from outside.
nc -vz {IP_OR_COMPUTER_NAME} 24224
- Create .pem from .pfx certificate
openssl pkcs12 -in file.pfx -out file.pem -nodes
- Find where the environment variable is set
grep -r VARIABLE_NAME /etc/*
- Extract private key from pfx and remove passphrase using OpenSSL (Use GitBash)
winpty openssl pkcs12 -in 1.pfx -clcerts -nokeys -out 1.cer
winpty openssl pkcs12 -in 1.pfx -nocerts -out 1.private.key
winpty openssl rsa -in 1.private.key -out 1.key
Comments
If you have any question, you can start a new discussion.