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

Blog    

Recommend

How to configure MySQL on Ubuntu 16.04 server and enable remote connection

background I am learning nodejs recently, and I r...

CSS3 flip card number sample code

I received a task from the company today, and the...

Detailed explanation of how to dynamically set the browser title in Vue

Table of contents nonsense text The first router/...

Introduction to using data URI scheme to embed images in web pages

The data URI scheme allows us to include data in a...

One line of code teaches you how to hide Linux processes

Friends always ask me how to hide Linux processes...

How to import/save/load/delete images locally in Docker

1. Docker imports local images Sometimes we copy ...

Introduction to the use of em in elastic layout in CSS3: How many pixels is 1em?

I have been using CSS for a long time, but I have...

Nginx proxy axios request and precautions

Preface I recently wrote a small demo. Because I ...

How to prevent event bubbling in JavaScript

What we need to pay attention to is that the char...

The forgotten button tag

Note: This article has been translated by someone ...

An example of vertical centering of sub-elements in div using Flex layout

1. Flex is the abbreviation of Flexible Box, whic...