Common Commands for Linux Ubuntu Docker

cd /          # Enter the root directory
pwd           # Print the current directory (command meaning: print work direction)
ls            # Display all files
nano 文件名称  # Edit and open a file                # After editing, save using keys CTRL+O  enter  CTRL+X
rm -r         # Delete a folder
mkdir         # Create a new folder
# Write content to a file path
sudo tee 写入文件路径 <<-'EOF'  Write the content of the file  EOF
exit          # Exit remote connection

# Docker related commands
docker ps      # View currently running containers
docker ps -a   # View all containers, including stopped ones
docker stop [container_name_or_ID]    # Stop a container
docker rm [container_name_or_ID]      # Delete a container
docker images # View images
docker rmi [image_name_or_ID]     # Delete an image
docker logs [container_name_or_ID]    # View container logs
docker volume ls           # View mounted volumes

# File upload and download
# Upload from local to server path
scp local_file.txt username@server_ip:/remote/directory/
# Download file from server to local current directory (default port 22)
scp username@server_ip:/remote/directory/report.txt .
# Specify port
scp -P port_number username@server_ip:/remote/directory/report.txt .

# Firewall related commands
ufw status        # View firewall status
ufw allow 22/tcp  # Add allow rule, port 22 is the default port for SSH connection
ufw  reload       # Restart the firewall
ufw disable       # Disable the firewall
ufw enable        # Enable the firewall

# Project deployment using docker-compose
# Enter the project root directory to start running
# Specify yml file (e.g., docker-compose.production.yml)
docker compose -f your-compose-file.yml -p [project_name] up -d # Default yml file (file name is docker-compose.yml)
docker compose -p [project_name] up -d

Leave a Comment