Fading Coder

One Final Commit for the Last Sprint

Home > Tech > Content

Resolving MySQL Container Startup Failure: Failed to Create Socket for IPv4 (errno 13)

Tech 1

Analysis

On an Ubuntu 20 server, a MySQL container based on Docker had been running stably. However, after installing Apache2 and MySQL directly via apt on Linux, restarting the MySQL container failed.

When encountering a problem, first check the container's error logs. Execute the log view command: docker logs -f -t --tail 10 mysql01

Log content: Error log

As seen, the container reported an error at creation. After searching online, the cause is often attributed to: IP address or port being occupied.

Presumably, the previously installed Apache2 or MySQL on Linux caused the network port to be occupied, so stopping these services should resolve the issue.

1. Stopping Apache2 and MySQL on Linux

1.1 Stop the services

sudo systemctl stop apache2
sudo systemctl stop mysql

# Or if using an older version of Ubuntu, you might use the service command:
# sudo service mysql stop
# sudo service apache2 stop

After this, restart the MySQL container in Docker:

docker start mysql01

However, the container still fails with the same error. Check the logs again.

1.2 Remove the packages

If stopping services does not help, completely remove the apt packages:

# 1. List MySQL-related packages
apt list --installed | grep mysql
# 2. Remove all MySQL packages
apt remove --purge mysql-server mysql-client mysql-common

# 3. List Apache2-related packages
apt list --installed | grep apache2
# 4. Remove all Apache2 packages
apt remove --purge apache2-bin apache2-data apache2-utils

After removal, verify no remnants:

apt list --installed | grep mysql
apt list --installed | grep apache2

No packages left

1.3 Start the MySQL container

After steps 1 and 2, start the MySQL container again:

docker start mysql01  # mysql01 is container name; can use container ID
docker logs -f -t --tail 10 mysql01  # view logs

The logs show normal startup: Container started successfully

2. Stopping Apache2 and MySQL on Windows

Open Services, find the MySQL service that occupies the port, and stop it. Stop MySQL service

Then start the desired MySQL service. Start MySQL service

Tags: Linux

Related Articles

Understanding Strong and Weak References in Java

Strong References Strong reference are the most prevalent type of object referencing in Java. When an object has a strong reference pointing to it, the garbage collector will not reclaim its memory. F...

Comprehensive Guide to SSTI Explained with Payload Bypass Techniques

Introduction Server-Side Template Injection (SSTI) is a vulnerability in web applications where user input is improper handled within the template engine and executed on the server. This exploit can r...

SBUS Signal Analysis and Communication Implementation Using STM32 with Fus Remote Controller

Overview In a recent project, I utilized the SBUS protocol with the Fus remote controller to control a vehicle's basic operations, including movement, lights, and mode switching. This article is aimed...

Leave a Comment

Anonymous

◎Feel free to join the discussion and share your thoughts.