WordPress can be blazing fast - if you run it on a VPS and optimize it properly. In this article, we explore how to unlock its full potential: from choosing the...
3v-Hosting Blog
7 min read
Docker is the platform of choice for developing, shipping and running applications in isolated environments called containers. Containers are a lightweight, portable and efficient alternative to traditional virtual machines, making it easier to manage dependencies and ensure consistency across different environments.
This article serves as a comprehensive Docker cheat sheet, covering essential commands for managing containers, images, volumes, networks and more. Whether you're a beginner or an experienced developer, these commands will help you efficiently work with Docker.
Before using Docker, ensure that it is installed on your system. You can verify the installation by running:
docker --version
To check the Docker service status, use:
systemctl status docker
If Docker is not running, start it with:
sudo systemctl start docker
For non-root users, Docker commands may require sudo. To avoid this, add your user to the docker group:
sudo usermod -aG docker $USER
Then, restart your session or log out and log back in.
Docker images are pre-packaged applications and dependencies required to create containers.
To find a specific image in Docker Hub:
docker search <image-name>
For example:
docker search ubuntu
To download an image from Docker Hub:
docker pull <image-name>
Example:
docker pull nginx
To pull a specific version:
docker pull nginx:1.21
To view all available images on your system:
docker images
To delete an image:
docker rmi <image-id>
If a container is using the image, it must be stopped and removed before deleting the image.
Containers are running instances of Docker images.
To create and start a container:
docker run <image-name>
For example:
docker run ubuntu
To run a container in interactive mode:
docker run -it ubuntu bash
To run a container in detached mode:
docker run -d nginx
To see active containers:
docker ps
To list all containers, including stopped ones:
docker ps -a
To stop a container:
docker stop <container-id>
To remove a stopped container:
docker rm <container-id>
To remove all stopped containers:
docker container prune
To restart a container:
docker restart <container-id>
To attach to a running container:
docker attach <container-id>
To run a command inside an active container:
docker exec <container-id> <command>
Example:
docker exec -it <container-id> bash
Docker volumes allow data to persist between container restarts.
To create a volume:
docker volume create my_volume
To list available volumes:
docker volume ls
To mount a volume to a container:
docker run -d -v my_volume:/data ubuntu
To inspect volume details:
docker volume inspect my_volume
To remove a volume:
docker volume rm my_volume
To remove all unused volumes:
docker volume prune
Docker networks enable communication between containers.
To see existing networks:
docker network ls
To create a new network:
docker network create my_network
To remove a network:
docker network rm my_network
To connect a running container to a network:
docker network connect my_network <container-id>
To disconnect a container from a network:
docker network disconnect my_network <container-id>
Docker Compose allows defining multi-container applications with a docker-compose.yml file.
To start all services defined in the Compose file:
docker-compose up -d
To stop all services:
docker-compose down
To restart services:
docker-compose restart
To see running services:
docker-compose ps
To check logs for all services:
docker-compose logs
For logs of a specific service:
docker-compose logs <service-name>
Docker provides several commands to manage system resources.
To check system-wide usage:
docker system df
To view container resource consumption:
docker stats
To clean up unused images, containers, and volumes:
docker system prune
To remove all unused images:
docker image prune -a
This Docker cheat sheet is your practical reference for essential Docker commands. It covers images, containers, volumes, networks and system management. Master these commands to improve your efficiency and control over Docker. Deploy microservices, manage cloud infrastructure or work with local development environments. Integrate these commands into your workflow to simplify application deployment and ensure consistency across different environments. For more advanced usage, learn about Docker Swarm, Kubernetes, and container security best practices.
Accelerating WordPress at the Nginx level: correct PHP-FPM settings, try_files, static files, caching, Brotli, wp-login protection, and secure headers for stabl...
Effective backup strategies for Docker applications: how to protect volumes, data, and configurations while avoiding common mistakes, and quickly restore servic...
A clear guide to what VPS is used for: real cases, examples for developers, business setups, VPN, CI/CD and more. Learn how to choose the right VPS plan.