Install Docker
We will use the shell script from Docker
Linux
|
|
Mac
|
|
💡 If you don’t have Homebrew installed, you can install it by running the following command in your macOS terminal:
|
|
Windows
For Windows, Docker provides a desktop version that simplifies the installation process.
- Go to the Docker Desktop download page.
- Download the Docker Desktop installer for Windows.
- Run the installer and follow the on-screen instructions.
Once installed, Docker Desktop should automatically start, and you can verify the installation by opening a terminal and running:
|
|
Fix Docker Permission Denied
If you encounter a “Permission Denied” error when running Docker commands, it may be due to Docker requiring root privileges. To fix this and allow Docker to run as a non-root user, follow these steps:
References: StackOverflow Docker Documentation
- Add your user to the
dockergroup:
|
|
- Apply the new group membership:
|
|
- Restart Docker to apply the changes:
|
|
This will allow you to run Docker commands without using sudo.
Root
If you need to run Docker as the root user, you can do so by prefixing Docker commands with sudo. However, this method is not recommended for security reasons.
Rootless
If you prefer to use Docker without requiring root privileges, you can follow the official guide to set up Docker in rootless mode. This method allows users to run Docker without needing sudo at all, offering a more secure environment. To learn more, check out the Rootless Docker documentation.
Docker Usage Example
Once Docker is installed and running, you can start using it to create and manage containers. Here’s an example of how to run a simple Docker container:
- Pull an image from Docker Hub:
|
|
- Run the container:
|
|
This will download the hello-world image from Docker Hub (if not already present) and run it inside a container. The output will display a welcome message confirming that Docker is working.
- List running containers:
|
|
- List all containers (including stopped ones):
|
|
- Stop a running container:
|
|
Replace <container_id> with the actual ID of the container you want to stop, which you can find by running docker ps.
Docker Mirror for Users in China
If you’re located in China, you might experience difficulties pulling Docker images due to the country’s ban on Docker Hub. To resolve this, you can configure Docker to use a mirror source.
Tencent Docker Mirror (Tencent VPS only)
Tencent offers a reliable Docker mirror for users in China. To use it, follow these steps:
- Edit or create the Docker daemon configuration file at
/etc/docker/daemon.json:
|
|
- Add the following configuration to use Tencent’s mirror:
|
|
- Save the file and restart Docker:
|
|
Now, Docker will use the Tencent mirror when pulling images, improving speed and reliability for users in China.
Additional Mirrors
If you’d like more options, here are some other popular Docker mirrors:
- Aliyun (Alibaba Cloud) Docker Mirror:
|
|
- On Mac Reference:
- Stackoverflow
- Docker
The config file is stored in the following path
~/.docker/daemon.json
You can add other sources
|
|