How to Deploy MySQL 8.0 in Docker on veLinux2 – Step‑by‑Step Guide
This guide walks through deploying MySQL 8.0 in a Docker container on veLinux 2, covering environment requirements, configuring a domestic Docker mirror, pulling the image, running the container with persistence and remote‑access settings, opening firewall ports, granting remote root privileges, and verifying the service.
Prerequisites
Server: veLinux 2 (EL9 architecture, 2 CPU, 4 GB RAM)
Deployment method: Docker container (avoids system dnf/rpm issues)
Database version: MySQL 8.0 stable
Advantages: no system modifications, stable deployment, data persistence, remote connection support
Preparation
Ensure Docker is installed (run docker --version)
Open network ports (system firewall + cloud security group)
No need to uninstall existing databases; the container is fully isolated from the host environment
Configure Docker mirror (required for fast image pull)
Docker’s default overseas registry is slow; execute the following commands to set domestic mirrors:
# create docker config directory
mkdir -p /etc/docker
# write mirror configuration
tee /etc/docker/daemon.json <<'EOF'
{
"registry-mirrors": [
"https://docker.1ms.run",
"https://hub-mirror.c.163.com",
"https://mirror.baidubce.com"
]
}
EOF
# reload daemon and restart Docker
systemctl daemon-reload
systemctl restart docker
# verify configuration
docker infoSeeing a “Registry Mirrors” field in the output confirms success.
Pull MySQL 8.0 image
docker pull mysql:8.0Wait until the pull finishes without errors.
Run MySQL 8.0 container (production‑grade configuration)
The command includes auto‑restart, port mapping, data persistence, and a custom root password. Execute:
docker run -d \
--name mysql8 \
--restart=always \
-p 3306:3306 \
-v /opt/mysql-data:/var/lib/mysql \
-e MYSQL_ROOT_PASSWORD=root@mysql \
mysql:8.0Parameter explanation
--name mysql8: container name for easy management --restart=always: Docker auto‑restart on boot or crash -p 3306:3306: maps host port 3306 to container, enabling remote connections -v /opt/mysql-data:/var/lib/mysql: persists data on the host; data survives container removal or restart -e MYSQL_ROOT_PASSWORD=root@mysql: sets the root password (customizable)
Open port 3306 (required for remote access)
1. Open firewall
firewall-cmd --add-port=3306/tcp --permanent
firewall-cmd --reload2. Configure cloud security group
In the Volcano Engine console, add an inbound rule for TCP port 3306; otherwise external tools cannot connect to the database.
Configure MySQL remote access
MySQL 8 disables remote root login by default; grant permission with the following steps:
# enter MySQL shell
docker exec -it mysql8 mysql -uroot -proot@mysql
# run SQL statements
CREATE USER 'root'@'%' IDENTIFIED BY 'root@mysql';
GRANT ALL PRIVILEGES ON *.* TO 'root'@'%';
FLUSH PRIVILEGES;
exit;Verify MySQL status and version
1. Check container status
docker ps | grep mysql8Output showing “Up …” indicates the container is running normally.
2. Show MySQL version
docker exec -it mysql8 mysql -uroot -proot@mysql -e "SELECT VERSION();"Signed-in readers can open the original source through BestHub's protected redirect.
This article has been distilled and summarized from source material, then republished for learning and reference. If you believe it infringes your rights, please contactand we will review it promptly.
liandk
Seasoned Java and mobile developer with years of experience, specializing in mini‑programs, public accounts, and full‑stack front‑end development. In the AI era, I continuously learn to broaden my knowledge and evolve. I revived a public account I started a decade ago during a dessert‑startup venture, using code as a vessel and knowledge as a companion. I share personal projects, technical articles, programming tips, and growth insights—let’s improve together and set sail.
How this landed with the community
Was this worth your time?
0 Comments
Thoughtful readers leave field notes, pushback, and hard-won operational detail here.
