(Method 2) Using Docker to Build a MySQL Docker Image
Installing the MySQL Database
For details about how to install the MySQL database on the physical machine, see Installing MySQL on a Physical Machine. You are advised to install the MySQL database by compiling the source code.
Creating a MySQL Docker Image
Run the supermin5 command to build a Docker image of the OS. The following uses the custom image openeuler-20.03-sp1-aarch64 as an example. The yum, net-tools, initscripts, and vi commands are pre-installed in the image. After the build is complete, submit the image.
- /usr/local/mysql in 4 is the MySQL installation package compiled in 5.3. Replace it with the actual path of the installation package.
- openeuler-20.03-sp1-aarch64.tar is the TAR image package in 5. Replace it with the actual package name.
- openeuler-20.03-sp1-aarch64 is the image name in 6. Replace it with the actual image name.
- Install the supermin tool.
1yum install supermin* -y
- Prepare the software package to be installed and save it in the supermin.d directory.
- CentOS
1 2
yum install net-tools supermin5 -v --prepare bash yum net-tools initscripts vi coreutils -o supermin.d
- openEuler
1supermin -v --prepare bash yum net-tools initscripts vi coreutils -o supermin.d
- CentOS
- Create an image and save it in the appliance.d directory.
- CentOS
1supermin5 -v --build --format chroot supermin.d -o appliance.d
- openEuler
1supermin -v --build --format chroot supermin.d -o appliance.d
- CentOS
- Copy the MySQL installation package compiled in Installing the MySQL Database.
1cp -r /usr/local/mysql appliance.d/usr/local/
- Build the image.
1tar --numeric-owner -cpf openeuler-20.03-sp1-aarch64.tar -C appliance.d/ .
- Import the image to the container.
1cat openeuler-20.03-sp1-aarch64.tar | docker import - openeuler-20.03-sp1-aarch64
- Run the Docker command to view the image.
1docker images | grep openeuler-20.03-sp1-aarch64
Starting the MySQL Docker Container
- Run a container instance by using the image. Create a container and run it in the background.
1docker run -itd --name mysql openeuler-20.03-sp1-aarch64 bash
- View the running container.
1docker ps - Log in to the container.
1docker exec -it mysql bash
Parent topic: Installing MySQL in a Docker Container