A brief analysis of the problem of mysql being inaccessible when deployed with docker-compose

A brief analysis of the problem of mysql being inaccessible when deployed with docker-compose

What is Docker-Compose

The Compose project originated from the previous fig project. It is written in Python and has a high degree of compatibility with docker/swarm. Compose is a tool for orchestrating Docker containers. It defines and runs multi-container applications. Multiple containers can be started with one command. Using Docker Compose, you no longer need to use shell scripts to start containers. Compose manages multiple Docker containers through a configuration file. In the configuration file, all containers are defined through services, and then the docker-compose script is used to start, stop, and restart the application, the services in the application, and the containers of all dependent services. It is very suitable for scenarios where multiple containers are combined for development. The default template file for docker-compose is docker-compose.yml, in which each service defined must be automatically built by specifying an image through the image instruction or the build instruction (Dockerfile is required).

Using Compose basically involves the following three steps:

1. Define your application environment in a Dockerfile so that it can be replicated anywhere.
2. Define the services that make up your application in docker-compose.yml so that they can run together in an isolated environment.
3. Finally, run docker-compose up and Compose will start and run the entire application.

Let's look at the problem that mysql cannot be accessed when deployed by docker-compose.

This problem has troubled me for a long time. After using docker-compose to deploy mysql, after the container is built, it can be accessed using mysql -u root -p , but it cannot be connected using the sql client. So I searched for a lot of information on Google and finally found that adding command: --default-authentication-plugin=mysql_native_password can solve this problem. It is still related to the password encryption method.

version: "3.3"
services:
 Redis:
 image: sameersbn/redis:latest
 ports:
  - "6379:6379"
 volumes:
  - redis_data:/var/lib/redis
 restart: always
 mysql:
  image: mysql:latest
  restart: always
  command: --default-authentication-plugin=mysql_native_password #This line of code solves the problem of inaccessible networks:
   -dev
  ports:
   - "3306:3306"
  environment:
   MYSQL_ROOT_PASSWORD: abc123
   MYSQL_USER: 'test'
   MYSQL_PASS: 'test'
  volumes:
   -mysql_data:/var/lib/mysql
networks:
 dev:
  driver: bridge
volumes:
 redis_data:
 mysql_data:

Summarize

The above is the problem of inaccessible mysql deployment using docker-compose that I introduced to you. I hope it will be helpful to you. If you have any questions, please leave me a message and I will reply to you in time. I would also like to thank everyone for their support of the 123WORDPRESS.COM website!

You may also be interested in:
  • Explain the deployment and configuration of Clickhouse Docker cluster with examples
  • Detailed explanation of docker-compose deployment php project example
  • Docker-compose one-click deployment of gitlab Chinese version method steps
  • How to deploy gitlab using Docker-compose
  • Tutorial on how to quickly deploy clickhouse using docker-compose

<<:  Based on vue-simple-uploader, encapsulate the global upload plug-in function of file segment upload, instant upload and breakpoint resume

>>:  Instructions for recovering data after accidental deletion of MySQL database

Recommend

Summary of various methods for Vue to achieve dynamic styles

Table of contents 1. Ternary operator judgment 2....

Basic use of subqueries in MySQL

Table of contents 1. Subquery definition 2. Subqu...

select the best presets to create full compatibility with all browsersselect

We know that the properties of the select tag in e...

Html to achieve dynamic display of color blocks report effect (example code)

Use HTML color blocks to dynamically display data...

Drop-down menu and sliding menu design examples

I found a lot of websites that use drop-down or sl...

Vue Page Stack Manager Details

Table of contents 2. Tried methods 2.1 keep-alive...

A brief discussion on several situations where MySQL returns Boolean types

mysql returns Boolean type In the first case, ret...

When modifying a record in MySQL, the update operation field = field + string

In some scenarios, we need to modify our varchar ...

Implementation of multiple instances of tomcat on a single machine

1. Introduction First of all, we need to answer a...

The whole process record of introducing Vant framework into WeChat applet

Preface Sometimes I feel that the native UI of We...

js version to realize calculator function

This article example shares the specific code of ...

Application of HTML and CSS in Flash

Application of HTML and CSS in Flash: I accidental...

The shortest JS to determine whether it is IE6 (IE writing method)

Commonly used JavaScript code to detect which ver...