Simple steps to create a MySQL container with Docker

Simple steps to create a MySQL container with Docker

Preface

We have already installed Docker and have a brief understanding of Docker. Here are some simple steps to create a MySQL container with Docker. Without further ado, let's take a look at the detailed introduction.

The steps are as follows

1. Start the docker service

[root@docker ~]# systemctl start docker

2. View the image in docker

[root@docker ~]# docker images
REPOSITORY TAG IMAGE ID CREATED SIZE
centos/mysql-57-centos7 latest 2e4ddfafaa6f 6 months ago 445MB
gogs/gogs-latest 2fb3b88053d6 6 months ago 94.2MB

3. Search for the image name you want to query

[root@docker ~]# docker search mysql
NAME DESCRIPTION STARS OFFICIAL AUTOMATED
mysql MySQL is a widely used, open-source relation… 7854 [OK]    
mariadb MariaDB is a community-developed fork of MySQL… 2604 [OK]    
cloudfoundry/cf-mysql-ci Image used in CI of cf-mysql-release 0 
[root@localhost ~]# docker pull mysql ---------------------Download the latest version by default [root@localhost ~]# docker pull mysql:5.7--------------------Download the specified version

4. Create and run a mysql container

[root@docker ~]# docker run -di --name=test_mysql -p 3306:3306 -e MYSQL_ROOT_PASSWORD=root centos/mysql-57-centos7
d7e5f99b502a904a970026e90227e186107e3b5d0baeaa93491af12cd7317b99
run: create and run -di: create in daemon mode --name: give the container a name -p: port mapping -e: initialize the Mysql user and set the root password to root

The last thing to fill in is the name of the image. If you do not specify a version, the latest one will be created by default.

5. View running containers

[root@docker ~]# docker ps
CONTAINER ID IMAGE COMMAND CREATED STATUS PORTS NAMES
d7e5f99b502a centos/mysql-57-centos7 "container-entrypoint..." 5 seconds ago Up 4 seconds 0.0.0.0:3306->3306/tcp test_mysql

6. You can use the database tool on your computer to connect to the database in the virtual machine

IP is the IP connected to the virtual machine, account: root, password: root

7. In fact, as long as you can pull a mirror, the others are similar (such as redis, mogodb, rabbitmq, etc.)

Summarize

The above is the full content of this article. I hope that the content of this article will have certain reference learning value for your study or work. Thank you for your support of 123WORDPRESS.COM.

You may also be interested in:
  • Solution to the problem of not being able to obtain the hostname of the host in the docker container
  • Directory permissions when creating a container with Docker
  • Detailed explanation of creating a MySQL container with Docker and connecting to the container through the command line
  • How to create a MySQL container with Docker
  • Detailed process of modifying hostname after Docker creates a container

<<:  Detailed explanation of this reference in React

>>:  mysql5.7.17 installation and configuration example on win2008R2 64-bit system

Recommend

MySQL 8.0.20 installation and configuration detailed tutorial

This article shares with you a detailed tutorial ...

HTML uses regular expressions to test table examples

Here is an example code for using regular express...

Summary of how to use the MySQL authorization command grant

How to use the MySQL authorization command grant:...

Docker mounts local directories and data volume container operations

1. Docker mounts the local directory Docker can s...

Troubleshooting of master-slave delay issues when upgrading MySQL 5.6 to 5.7

Recently, when upgrading the Zabbix database from...

HTML Code Writing Guide

Common Convention Tags Self-closing tags, no need...

4 solutions to mysql import csv errors

This is to commemorate the 4 pitfalls I stepped o...

Example code for evenly distributing elements using css3 flex layout

This article mainly introduces how to evenly dist...

Implementation of scheduled backup in Mysql5.7

1. Find mysqldump.exe in the MySQL installation p...

Mysql aggregate function nested use operation

Purpose: Nested use of MySQL aggregate functions ...

MySQL graphical management tool Navicat installation steps

Table of contents Preface 1. Arrange the installa...

Detailed steps for installing MySQL using cluster rpm

Install MySQL database a) Download the MySQL sour...