Home > Database > Mysql Tutorial > body text

How docker creates a centos container and downloads MySQL for local connection

WBOY
Release: 2023-05-31 16:26:41
forward
814 people have browsed it

    1. Pull the image

    docker pull guyton/centos6     #因为是docker命令,所以命令前加docker
    Copy after login

    2. Check whether the pull is successful

    docker images   #查看所有镜像
    Copy after login

    3. Several methods of creating docker containers

    Method 1: (Recommended for novices) Step by step creation

    #依赖guyton/centos6创建一个名为mycentos_mysql的容器,并存在/bin/bash目录
     
    docker create -it --name mycentos_mysql guyton/centos6 /bin/bash
     
    #查看是否创建成功
    docker ps -a
     
    #启动容器(进入容器前必须启动容器)
    docker start mycentos_mysql
     
    #进入容器
    docker attach mycentos_mysql
    Copy after login

    Method 2: (Create and enter the container)

    docker run -it --name mycentos_mysql guyton/centos6
    Copy after login

    Method 3: (Create and set up the port directly and then Enter the container) Set up a port to facilitate local connection to MySQL

    docker run -it --name mycentos_mysql -p 3307:3306 guyton/centos6
    Copy after login

    4. Download MySQL in the container

    After entering the container, download MySQL. There is a high probability of encountering problems. Solutions will be provided later. Write:

    #下载MySQL
    yum install -y mysql mysql-devel mysql-server
    #报错,下载不了
     
    #更换一下yum源,依次在容器里输入以下代码
    sed -i "s|enabled=1|enabled=0|g" /etc/yum/pluginconf.d/fastestmirror.conf
     
    mv /etc/yum.repos.d/CentOS-Base.repo /etc/yum.repos.d/CentOS-Base.repo.backup
     
    curl -o /etc/yum.repos.d/CentOS-Base.repo https://www.xmpan.com/Centos-6-Vault-Aliyun.repo
     
    yum clean all && yum makecache
     
    #更换完yum源后,再次尝试下载MySQL,下载成功。
    Copy after login

    How docker creates a centos container and downloads MySQL for local connection

    5. Start MySQL and enter MySQL

    #启动 
    service mysqld start
     
    #进入
    mysql -uroot -p
    Copy after login

    If a green ok appears, it means the startup is successful. The first time There is no password to enter MySQL. Ignore the prompt to enter the password. Just press Enter and enter

    How docker creates a centos container and downloads MySQL for local connection

    6. Configure permissions

    #复制mysql>后面的代码就可以
     
    mysql> GRANT ALL ON *.* TO root@'%' IDENTIFIED BY '1' WITH GRANT OPTION;
     
    mysql> FLUSH PRIVILEGES;
    Copy after login

    Then you can open the local connection Software, such as MySQL, or Navicat Premium

    Enter the IP of the virtual machine and the previously set port number. The username and password are the username and password of the virtual machine, and then Once the connection is successful, you can start using it

    How docker creates a centos container and downloads MySQL for local connection

    The above is the detailed content of How docker creates a centos container and downloads MySQL for local connection. For more information, please follow other related articles on the PHP Chinese website!

    Related labels:
    source:yisu.com
    Statement of this Website
    The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
    Popular Tutorials
    More>
    Latest Downloads
    More>
    Web Effects
    Website Source Code
    Website Materials
    Front End Template