looks like dockerhub is blocked in China main land, how the main land people to pull image from dockerhub?
Assistant
Accessing Docker Hub from mainland China can indeed be troublesome due to restrictions put in place by the Chinese government. However, there are multiple ways individuals and organizations can work around these issues:
User
please share the aliyun and daoclount mirror url and config
Assistant
Certainly! Below are the URLs and the configuration steps to set up both Aliyun (Alibaba Cloud) and DaoCloud Docker Hub mirrors.
The configuration you provided appears mostly correct, but it's important to ensure the formatting is proper and there are no issues with the syntax or structure. Here's a corrected version of the configuration file to ensure it follows best practices:
The key insecure-registries should be used instead of .
User
failed to start docker with "
Jul 11 09:01:18 k8sm dockerd-current[2189]: unable to configure the Docker daemon with file /etc/docker/daemon.json: the fo...
Jul 11 09:01:18 k8sm systemd[1]: docker.service: main process exited, code=exited, status=1/FAILURE
"
Assistant
User
ystemctl reload daemon
Failed to reload daemon.service: Unit not found. how to fix it
Assistant
The error message Failed to reload daemon.service: Unit not found. suggests that you are attempting to reload a service named daemon, which does not exist. The correct command is , not .
Use a VPN: This is a common method to circumvent internet restrictions. A VPN routes your internet connection through servers in another country, allowing access to blocked services. Note that using a VPN may be subject to local regulations.
Use Mirror Services: Some Chinese companies offer mirror services for Docker images. These mirrors replicate Docker Hub content and are accessible from within mainland China. Examples include:
DaoCloud: It offers a mirror for Docker images.
ALIYUN (Alibaba Cloud): Provides its own container registry service that mirrors Docker images.
Private Registries: Organizations can set up their own Docker registry to host and manage Docker images. This private registry can be used for internal distribution, avoiding the need to access Docker Hub directly. Examples include:
Harbor: An open-source container image registry that secures artifacts with policies and role-based access control.
JFrog Artifactory: A universal repository manager that supports Docker images.
Use Docker's China-specific Registry: Docker has launched a China-specific registry in partnership with companies like Alibaba Cloud. This registry can sometimes offer better access and performance for users in China.
To set Docker to use a mirror, you can configure it through the Docker daemon configuration file typically located at /etc/docker/daemon.json, adding the mirror details. For example:
Download Images Elsewhere and Transfer: If direct access or mirrors aren’t suitable, another option is to download Docker images from Docker Hub outside of China and then transfer these images to systems inside China via other means, such as secure FTP, USB drives, or other file transfer methods.
By adopting one or a combination of these methods, users in mainland China can pull Docker images despite Docker Hub being blocked.
Mirror URL: Aliyun provides several regional mirror URLs. The most commonly used one is as follows:
Configuration: To configure Docker to use the Aliyun mirror, edit the Docker daemon configuration file, typically located at /etc/docker/daemon.json, and add the following:
Mirror URL: DaoCloud provides the following mirror URL:
Mirror URL: https://docker.mirrors.ustc.edu.cn
Configuration: To configure Docker to use the DaoCloud mirror, edit the Docker daemon configuration file at /etc/docker/daemon.json, and add the following:
Again, restart Docker to apply the configuration changes:
sh
sudo systemctl restart docker
By configuring these mirrors, you should be able to pull Docker images more effectively within mainland China.
insecure-registry
Ensure the structure is properly formatted with the confirmed correct key name intended for Docker configuration.
Steps to Edit and Apply the Configuration File:
Edit Configuration File: Use a text editor to edit /etc/docker/daemon.json. You can use vim, nano, or any other text editor you're comfortable with. For example, using nano:
sh
sudo nano /etc/docker/daemon.json
Paste the Correct Configuration: Make sure your configuration file looks like the above corrected JSON.
Save and Exit: Save the changes and exit the text editor. In nano, you can save by pressing Ctrl + O, press Enter to confirm, and then exit by pressing Ctrl + X.
Restart Docker: Apply the changes by restarting the Docker service.
sh
sudo systemctl restart docker
By following these steps, you ensure that Docker is using the specified mirrors and allows for an insecure registry at 192.168.1.113:5000. This setup should help in effectively pulling Docker images from the mirrors and using your custom registry.
The error message suggests that there might be an issue with the configuration file syntax or content. Here are a few steps to troubleshoot and resolve the issue:
Check Syntax of /etc/docker/daemon.json:
Ensure there are no syntax errors in the JSON file. JSON is very strict about its format.
Use a JSON validator to ensure your configuration is correct. You can use online tools such as JSONLint or use a command-line tool like jq for validation:
sh
cat /etc/docker/daemon.json | jq .
If jq is not installed, you can install it using:
sh
sudo apt-get install jq # For Debian/Ubuntu
sudo yum install jq # For CentOS/RHEL
Check for Trailing Commas:
Make sure there are no trailing commas in the JSON file. JSON does not allow trailing commas at the end of arrays or objects.
Ensure Proper Permissions:
Ensure the Docker configuration file has the correct permissions. Typically, it should be readable by the Docker service.
sh
sudo chmod 644 /etc/docker/daemon.json
Review Docker Logs:
Check the Docker logs for more detailed error messages. This can give you more insight into what's going wrong.
sh
journalctl -u docker.service
Recreate the Configuration File:
If you suspect a hidden character or formatting issue, consider recreating the file from scratch. Delete the existing file and create a new one with the correct content.
If Docker still fails to start, consider reviewing /etc/docker/daemon.json for any anomalies. Also, check if any additional configurations or overrides are in place elsewhere (e.g., drop-in files in /etc/systemd/system/docker.service.d/).
By following these steps, you should be able to identify and fix the configuration issue causing Docker to fail on startup.
systemctl daemon-reload
systemctl reload daemon
Correct Command: systemctl daemon-reload
The daemon-reload command is used to reload the systemd manager configuration. This can be necessary after making changes to service configuration files or custom unit files.
Here are the proper steps:
Reload systemd Manager Configuration:
sh
sudo systemctl daemon-reload
Restart Docker Service:
sh
sudo systemctl restart docker
Example of Complete Steps to Reload and Restart Docker Service:
Edit Docker Configuration (if needed):
sh
sudo nano /etc/docker/daemon.json
Ensure the configuration file is correct; here is an example configuration:
Save and Close the File: Ensure there are no syntax errors, and save the file.
Reload systemd Configuration:
sh
sudo systemctl daemon-reload
Restart Docker Service:
sh
sudo systemctl restart docker
Check Docker Service Status (Optional but recommended):
After restarting, you may want to check the status of the Docker service to ensure it is running properly.
sh
sudo systemctl status docker
Example Output of sudo systemctl status docker:
sh
● docker.service - Docker Application Container Engine
Loaded: loaded (/lib/systemd/system/docker.service; enabled; vendor preset: enabled)
Active: active (running) since <date> <time>; <duration> ago
Docs: https://docs.docker.com
Main PID: 1234 (dockerd)
CGroup: /system.slice/docker.service
└─1234 /usr/bin/dockerd -H fd:// --containerd=/run/containerd/containerd.sock
Having completed these steps, the Docker service should be running with the new configuration. If you still encounter issues, reviewing the detailed logs with journalctl -u docker.service can provide more insight into any specific errors or issues.