How to Run MySQL container by Docker on Rocky Linux 8.6
- 00:22 cat /etc/os-release
- 00:40 systemctl status docker.service
- 00:57 docker pull mysql/mysql-server:latest
- 01:48 docker images
- 02:02 docker run -p 3307:3307 -d --name=mysqls
- 02:55 docker ps
- 03:10 docker exec -it mysqls bash
- 03:31 mysql -u root
- 03:53 docker logs mysqls
- 04:04 show databases;
- 04:27 ALTER USER 'root'@'localhost' IDENTIFIED BY 'root';
- 04:50 create database linuxhelp;
- 05:27 exit
To run MySQL container by Docker on Rocky Linux 8.6
A Docker container image is a lightweight, standalone, executable package and MySQL is the most widely adopted open source relational database.
Installation Procedure:
Step 1: Check the OS version by using the below command
[root@linuxhelp ~]# cat /etc/os-release
NAME="Rocky Linux"
VERSION="8.6 (Green Obsidian)"
ID="rocky"
ID_LIKE="rhel centos fedora"
VERSION_ID="8.6"
PLATFORM_ID="platform:el8"
PRETTY_NAME="Rocky Linux 8.6 (Green Obsidian)"
ANSI_COLOR="0;32"
CPE_NAME="cpe:/o:rocky:rocky:8:GA"
Step 2: Check the Docker status by using the below command
[root@linuxhelp ~]# systemctl status docker.service
● docker.service - Docker Application Container Engine
Loaded: loaded (/usr/lib/systemd/system/docker.service; disabled; vendor preset: disabled)
Active: active (running) since Fri 2022-07-22 02:35:59 EDT; 1 months 4 days ago
Docs: https://docs.docker.com
Main PID: 43049 (dockerd)
Tasks: 9
Memory: 47.0M
CGroup: /system.slice/docker.service
└─43049 /usr/bin/dockerd -H fd:// --containerd=/run/containerd/containerd.sock
Step 3: Pull the MySQL Docker Image by using the below command
[root@linuxhelp ~]# docker pull mysql/mysql-server:latest
latest: Pulling from mysql/mysql-server
cdd8b07c6082: Pull complete
c2f1720beca1: Pull complete
39f143a8d6de: Pull complete
118a8285b641: Pull complete
b45cbcaf75c7: Pull complete
d4574372e600: Pull complete
1f565a3cbc52: Pull complete
Digest: sha256:e30a0320f2e3c7b7ee18ab903986ada6eb1ce8e5ef29941b36ec331fae5f10b2
Status: Downloaded newer image for mysql/mysql-server:latest
docker.io/mysql/mysql-server:latest
Step 4: List the Docker images by using the below command
[root@linuxhelp ~]# docker images
REPOSITORY TAG IMAGE ID CREATED SIZE
mysql/mysql-server latest eb5713a2c247 4 weeks ago 428MB
hello-world latest feb5d9fea6a5 11 months ago 13.3kB
Step 5: Run the MySQL image by using the below command
[root@linuxhelp ~]# docker run -p 3307:3307 -d --name=mysqls mysql/mysql-server:latest
a7818c8489a2a226b02ce66155eb9693377beb693491ad258a4a7ef784552687
Step 6: Now check MySQL Docker Container by using the below command
[root@linuxhelp ~]# docker ps
CONTAINER ID IMAGE COMMAND CREATED STATUS PORTS NAMES
a7818c8489a2 mysql/mysql-server:latest "/entrypoint.sh mysq…" 16 seconds ago Up 14 seconds (health: starting) 3306/tcp, 33060-33061/tcp, 0.0.0.0:3307->3307/tcp, :::3307->3307/tcp mysqls
Step 7: Execute the MySQL container by using bash shell
[root@linuxhelp ~]# docker exec -it mysqls bash
Step 8: Get MySQL root password from Docker MySQL log files using the below command
[root@linuxhelp ~]# docker logs mysqls
[Entrypoint] MySQL Docker Image 8.0.30-1.2.9-server
[Entrypoint] No password option specified for new database.
[Entrypoint] A random onetime password will be generated.
2022-08-26T03:10:32.817870Z 0 [Warning] [MY-011068] [Server] The syntax '--skip-host-cache' is deprecated and will be removed in a future release. Please use SET GLOBAL host_cache_size=0
2022-08-26T03:10:32.817929Z 0 [System] [MY-013169] [Server] /usr/sbin/mysqld (mysqld 8.0.30) initializing of server in progress as process 16
[Entrypoint] Initializing database
2022-08-26T03:10:39.984183Z 0 [System] [MY-011323] [Server] X Plugin ready for connections. Socket: /var/run/mysqld/mysqlx.sock
[Entrypoint] GENERATED ROOT PASSWORD: r8#f*:&J8bezPS1y2Kl8?:mA8P?31G:B
Step 9: Login MySQL as root user by using the below command
bash-4.4# mysql -u root -p
Enter password:
Welcome to the MySQL monitor. Commands end with ; or \g.
Your MySQL connection id is 13
Server version: 8.0.30
Copyright (c) 2000, 2022, Oracle and/or its affiliates.
Oracle is a registered trademark of Oracle Corporation and/or its
affiliates. Other names may be trademarks of their respective
owners.
Type 'help;' or '\h' for help. Type '\c' to clear the current input statement.
Step 10: Next, change the MySQL root server password by using the below command
mysql> ALTER USER 'root'@'localhost' IDENTIFIED BY 'root';
Query OK, 0 rows affected (0.03 sec)
Step 11: Check the MySQL databases by using the below command
mysql> show databases;
+--------------------+
| Database |
+--------------------+
| information_schema |
| mysql |
| performance_schema |
| sys |
+--------------------+
4 rows in set (0.05 sec)
Step 12: Create the MySQL databases by using the below command
mysql> create database linuxhelp;
Query OK, 1 row affected (0.01 sec)
mysql> use linuxhelp;
Database changed
Step 13: Exit MySQL
mysql> exit
Bye
Conclusion:
We have reached the end of this article. In this guide, we have walked you through the steps required to run MySQL container by docker on rocky Linux 8.6. Your feedback is much welcome.
Comments ( 0 )
No comments available