Solution to the Docker container being unable to access the host port

Solution to the Docker container being unable to access the host port

I recently encountered a problem at work. The docker container could not access the host's redis, and the telent6379 port was blocked.

After investigation, it was found that the server had a firewall enabled, and the firewall authorized access to port 6379 to the docker0 network card.

The operation is as follows:

firewall-cmd --permanent --zone=trusted --change-interface=docker0

firewall-cmd --reload

Additional knowledge: Docker starts the mysql container and an error occurs: Ports are not available: listen tcp 0.0.0.0:3306

The error screenshot is as follows

This error is caused by the local port 3306 being occupied. It is likely that MySQL has been installed locally and the MySQL service has been started.

Solution 1: Open the service, find the mysql service, stop it, or change the port

Then execute the following command

docker run --name MYSQL -e MYSQL_ROOT_PASSWORD=123456 -p 3306:3306 -itd mysql:latest /bin/bash

As shown in the figure, the startup is successful

Solution 2: Change port mapping

docker run --name MYSQL -e MYSQL_ROOT_PASSWORD=123456 -p 3309:3306 -itd mysql:latest /bin/bash

illustrate:

-p 3309:3306: -p host port: container port, that is, map the host port 3309 to the container port 3306. When the host logs in to the container database, use the host port, such as 3309.

The above solution to the problem that the docker container cannot access the host port is all the content that the editor shares with you. I hope it can give you a reference, and I also hope that you will support 123WORDPRESS.COM.

You may also be interested in:
  • Docker enables seamless calling of shell commands between container and host
  • Solution to the Docker container not having permission to write to the host directory
  • Execute the shell or program inside the Docker container on the host
  • Call and execute host docker operations in docker container
  • Detailed explanation of how to solve the problem that the docker container cannot access the host machine through IP
  • How to use Docker container to access host network
  • Solve the problem of 8 hours difference between docker container and host machine

<<:  Detailed explanation of the watch listener example in vue3.0

>>:  How to set the width and height of html table cells

Recommend

How to configure SSL for koa2 service

I. Introduction 1: SSL Certificate My domain name...

js realizes two-way data binding (accessor monitoring)

This article example shares the specific code of ...

HTML adaptive table method

<body style="scroll:no"> <tabl...

Improvements to the web server to improve website performance

<br />In the first section of this series, w...

Tutorial on upgrading, installing and configuring supervisor on centos6.5

Supervisor Introduction Supervisor is a client/se...

Detailed usage of js array forEach instance

1. forEach() is similar to map(). It also applies...

Problems and solutions encountered when connecting node to mysql database

I installed a new version of MySQL (8.0.21) today...

How to fix abnormal startup of mysql5.7.21

A colleague reported that a MySQL instance could ...

Detailed explanation of setting Context Path in Web application

URL: http://hostname.com/contextPath/servletPath/...

Vue conditional rendering v-if and v-show

Table of contents 1. v-if 2. Use v-if on <temp...

Add a floating prompt for the header icon in the ElementUI table

This article mainly introduces how to add floatin...

Teach you how to use vscode to build a react-native development environment

question The code has no prompt: Many non-front-e...

Introduction to the deletion process of B-tree

In the previous article https://www.jb51.net/arti...

Detailed explanation of common commands in MySQL 8.0+

Enable remote access Enable remote access rights ...