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

Use Firebug tool to debug the page on iPad

How to debug a page on iPad? When using iOS 5, you...

UDP simple server client code example

I won’t go into details about the theory of UDP. ...

CSS overflow-wrap new property value anywhere usage

1. First, understand the overflow-wrap attribute ...

How to build lnmp environment in docker

Create a project directory mkdir php Create the f...

Hexadecimal color codes (full)

Red and pink, and their hexadecimal codes. #99003...

js to realize a simple disc clock

This article shares the specific code of js to im...

Summary of the differences and usage of plugins and components in Vue

The operating environment of this tutorial: Windo...

Detailed steps to build an independent mail server on Centos7.9

Table of contents Preface 1. Configure intranet D...

Sharing experience on the priority of CSS style loading

During the project development yesterday, I encoun...

Introduction to local components in Vue

In Vue, we can define (register) local components...

Python MySQL database table modification and query

Python connects to MySQL to modify and query data...

Detailed tutorial on uploading and configuring jdk and tomcat on linux

Preparation 1. Start the virtual machine 2. git t...

How to display div on object without being blocked by object animation

Today I made a menu button. When you move the mous...

Vue close browser logout implementation example

Table of contents 1. beforeunload event 2. Unload...

How to display small icons in the browser title bar of HTML webpage

Just like this effect, the method is also very si...