This guide provides detailed instructions on using Docker, including commands and solutions to common problems. The Docker commands provided in this guide are platform-independent and should work across different operating systems such as Ubuntu, Debian, and others. For installation instructions specific to your platform, please go to the official Docker documentation at docker.com.
- Docker Group Permissions
- Basic Docker Commands
- Managing Containers
- Accessing Containers
- Handling Container Issues
- Docker-Compose
- Backup and Restore
- Security Best Practices
- Additional Resources
- Your Support
- Force Stop and Remove All Containers
Ensure your user is part of the Docker group to have the necessary permissions:
sudo usermod -aG docker $USER
newgrp docker
docker ps -a
docker ps
docker start <container_id_or_name>
docker stop <container_id_or_name>
docker rm <container_id_or_name>
docker rm -f <container_id_or_name>
docker logs <container_id_or_name>
docker exec -it <container_id_or_name> <command>
sudo docker stop $(docker ps -aq)
sudo docker rm -f $(docker ps -aq)
sudo lsof -i -P -n | grep LISTEN
Sometimes restarting the Docker service can help resolve permission issues:
sudo systemctl restart docker
Find the container IDs and stop and remove them individually:
sudo docker stop d0ef74920923
sudo docker rm -f d0ef74920923
sudo docker stop 24f3cfc93042
sudo docker rm -f 24f3cfc93042
sudo dockerd --debug
Ensure the user is in the Docker group:
groups $USER
If problems persist, consider reinstalling Docker:
sudo apt-get purge docker-ce docker-ce-cli containerd.io
sudo apt-get install docker-ce docker-ce-cli containerd.io
sudo journalctl -u docker.service
docker exec -it <container_id_or_name> /bin/bash
docker cp <source_path> <container_id_or_name>:<destination_path>
docker cp <container_id_or_name>:<source_path> <destination_path>
Create a docker-compose.yml
file to define and run multi-container Docker applications:
version: '3.8'
services:
web:
image: php:7.4-apache
container_name: lamp-web
ports:
- "8080:80"
volumes:
- ./html:/var/www/html
networks:
- lamp-network
db:
image: mariadb:latest
container_name: lamp-mariadb
environment:
MYSQL_ROOT_PASSWORD: example_root_password
MYSQL_DATABASE: example_db
MYSQL_USER: example_user
MYSQL_PASSWORD: example_password
command: >
--default-authentication-plugin=mysql_native_password
volumes:
- ./mariadb_data:/var/lib/mysql
networks:
- lamp-network
phpmyadmin:
image: phpmyadmin/phpmyadmin
container_name: lamp-phpmyadmin
environment:
PMA_HOST: lamp-mariadb
PMA_USER: phpmyadmin_user
PMA_PASSWORD: phpmyadmin_password
ports:
- "8081:80"
networks:
- lamp-network
networks:
lamp-network:
driver: bridge
Navigate to the directory containing your docker-compose.yml
file and start the services:
cd /path/to/your/docker-compose/directory
docker-compose up -d
docker-compose ps
docker-compose down
docker exec lamp-mariadb /usr/bin/mysqldump -u example_user --password=example_password example_db > backup.sql
cat backup.sql | docker exec -i lamp-mariadb /usr/bin/mysql -u example_user --password=example_password example_db
tar czvf backup-html.tar.gz -C /path/to/your/html/files .
tar xzvf backup-html.tar.gz -C /path/to/your/html/files
Keep your system and Docker images updated regularly:
sudo apt-get update && sudo apt-get upgrade
docker pull php:7.4-apache
docker pull mariadb:latest
docker pull phpmyadmin/phpmyadmin
Use ufw
(Uncomplicated Firewall) to restrict access to specific ports:
sudo ufw allow OpenSSH
sudo ufw allow 8003
sudo ufw allow 8004
sudo ufw enable
Avoid using password authentication and use SSH keys instead.
For more detailed information, go to the official Docker documentation at docker.com.
If you find this project useful and want to support it, there are several ways to do so:
- If you find the white paper helpful, please ⭐ it on GitHub. This helps make the project more visible and reach more people.
- Become a Follower: If you're interested in updates and future improvements, please follow my GitHub account. This way you'll always stay up-to-date.
- Learn more about my work: I invite you to check out all of my work on GitHub and visit my developer site https://volkansah.github.io. Here you will find detailed information about me and my projects.
- Share the project: If you know someone who could benefit from this project, please share it. The more people who can use it, the better. If you appreciate my work and would like to support it, please visit my GitHub Sponsor page. Any type of support is warmly welcomed and helps me to further improve and expand my work.
Thank you for your support! ❤️
For developers and users who need to forcefully stop and remove all Docker containers, especially when dealing with containers with misconfigured permissions:
Ensure your user is part of the Docker group to have the necessary permissions:
sudo usermod -aG docker your_username
newgrp docker
groups your_username
sudo chmod 666 /var/run/docker.sock
sudo systemctl restart snap.docker.dockerd.service
docker run hello-world
sudo docker stop $(sudo docker ps -aq)
sudo docker rm $(sudo docker ps -aq) --force
sudo systemctl restart docker