A WordPress or MySQL container stops when its main process exits; Docker is reporting a symptom, not repairing the cause. Start with docker compose ps -a and the first fatal line from docker compose logs. Most failures come from a wrong database hostname, mismatched credentials, a database that was never created, MySQL still initializing, missing persistent volumes, an entrypoint or permission error, or an out-of-memory kill. Fix that underlying error first, then use a restart policy and health checks to make recovery dependable.
Antihost offers managed WordPress hosting with free migration, one-click staging and a 14-day free trial.
What a stopped container actually means
A container stays alive only while its primary process is running. In a typical WordPress stack, the WordPress image runs a web server in the foreground and the MySQL image runs the database server in the foreground. If either process exits, Docker marks that container as Exited. If a restart policy is configured, Docker starts it again, which can make the service appear to be randomly stopping when it is actually failing in a repeatable loop.
As an Amazon Associate I earn from qualifying purchases.
Quick wins for a faster PC:
Clear out junk files and repair common Windows errorsFree Scan →Fix the driver behind crashes, sound loss and screen glitchesFind Drivers →Repair Windows errors before they cause bigger problemsFix Now →The correct order is therefore: observe the state, read the logs, identify the first fatal error, and only then change configuration. Recreating containers or adding restart: always before reading the failure can hide the useful evidence and repeatedly restart a broken setup.
Diagnose the failure before changing Compose
1. Check every service, including exited containers
docker compose ps -a
Look at the State and Health columns for both services. Exited means the main process finished; Restarting indicates a restart loop; Up (healthy) means the configured health check is passing. If you omit -a, Compose normally shows only running containers and you can miss the event that stopped the service.
#1 Best Overall
- [Ultra-Lightweight Ear Buds Designed for Small Ears] Each earbud weighs only 3.7g and features a compact, ergonomic in-ear design made especially for small ears. Secure, low-profile, and comfortable for workouts, all-day wear or overnight sleeping.The ultra-slim profile sits flush in your ear with no hard edges poking or rubbing, so you can even sleep on your side without discomfort.
- [Immersive Stereo Sound with TOZO OrigX Technology] TOZO OrigX tuning delivers clear vocals, balanced mids, and natural stereo sound for music, podcasts, and videos.
- [Long Battery Life for Daily Use] Get up to 7 hours of playtime on a single charge, with up to 32 hours total using the charging case—ideal for workdays, commuting, and extended listening sessions.
- [Bluetooth 5.3 & Stable Connection] Bluetooth 5.3 provides fast pairing, stable wireless performance, and reduced dropouts as you move around home or office.
- [Deep Bass with Clear Vocals] High-performance drivers produce punchy bass while keeping vocals clean and detailed for everyday listening.
2. Read the first fatal log line
docker compose logs --tail=200 wordpress db
Read from the beginning of the relevant failure, not just the final line saying that Docker restarted a container. The attached form of docker compose up also streams service output while the stack starts:
docker compose up
For a container created outside the current Compose project, use its name or ID:
Free tools Windows power users keep installed
One-click scans. No signup required.
docker logs CONTAINER
Typical clues include “connection refused,” “unknown database,” authentication failures, a missing command or file, permission-denied messages, and an out-of-memory termination. A clean shutdown after a one-shot command is different: the command completed normally and the container has no long-running process to keep it alive.
3. Inspect the recorded exit state
docker inspect CONTAINER --format '{{json .State}}'
The state includes the exit code, whether Docker considers the container running, an error string, and (when applicable) an out-of-memory flag. An exit code of zero generally means the process chose to finish; nonzero values indicate an application or startup failure. Code 137 commonly accompanies an out-of-memory kill, while codes 126 or 127 often point to an unusable or missing command. Treat those numbers as clues and confirm them against the log and host metrics.
If the container disappears immediately after recreation, capture the output in attached mode or inspect the container before removing it. Do not run docker compose down -v as a routine diagnostic step: the -v option removes named volumes and can destroy the database and WordPress files.
Make WordPress address the right MySQL service
Use the Compose service name, not localhost
Inside the WordPress container, localhost refers to that same WordPress container. It does not refer to the MySQL container. Compose provides DNS for service names on the project network, so the host should normally be the database service name, such as db, optionally followed by its port:
The Tool Desk
Outbyte PC Repair FREERepair Windows errors before they cause bigger problemsFix Now →Outbyte Driver Updater FREEScan for outdated or missing drivers - takes under a minuteDriver Scan →WORDPRESS_DB_HOST: db:3306
Both services must be attached to the same Compose network. The default network created for a single Compose file is sufficient unless you deliberately override networks. A host name that works from your laptop, an IP address copied from a previous container, or 127.0.0.1 can all be wrong from WordPress’s point of view.
Rank #2
- 【IP68 Waterproof Multifunctinal Smart Watch】Torjalph fitness activity tracker smart watch is IP68 waterproof technology ,you can wear it when swimming,handwashing,it's rain-proof which means that you perform multiple exercise modes outside without worrying about sweat or rain corroding your fitness smart watch,and this watch equipped with a 230 mAh large capacity battery magnetic charging ,and this sports activity tracker watch can be used 5-7 days If fully charged.
- 【Larger 1.83'' Full Screen Watch & Multi-dial Selection】1.83 inch full HD color touch screen smart watch for men / women provides excellent 240*284 resolution image quality ,This Bluetooth smart watch offers a better touch experience and remarkable immersion and ,more than 200 watch faces for you to choose from App"Da Fit ", you can change the dial style according to your mood to wear keeping the world on your wrist
- 【Accurate Activity Tracker Smart Watch 】sports watch activity tracker uses sweat and dust resistant breathable silicone strap, our Fitness Tracker Smart Watch for Android iOS Phones supports 12 sports modes,walking,running,bicycle,swimming,badminton,basketball,football,rope skipping. This bluetooth calls smart watch for men women is lightweight and stylish, bringing more convenient and relaxing sports experience while also providing more protection.
- 【Your 24 Hour Personal Daily Health Monitor】Fitness watch for women men full touch screen IP67 waterproof bluetooth smartwatch for Android iOS Phones with heart rate blood pressure monitor multifunction Andriod smart watch with steps counter sleep monitor sports fitness watch, monitoring blood oxygen saturation allows you to understand your physical condition in real time to track fitness progress ,to know your health status in time.
- 【More Functions Bluetooth Call Smart Watch】This fitness activity smart watch full screen for iPhone and Android phones includes a bunch of new features including:The bluetooth smart watch can hang up the phone, receive and display WhatsAPP /Text /Facebook /Twitter /Messenger reminder.Support sedentary reminder, alarm clock, stopwatch, timer,weather information,music control, remote camera control compatible with Android 5.0 and above or iOS 9.0 and above smartphones.
Keep the four connection values consistent
WordPress receives its connection settings through four variables. MySQL uses corresponding initialization variables. The values must describe the same database and user:
| WordPress variable | Matching MySQL variable | What it controls |
|---|---|---|
WORDPRESS_DB_HOST |
Compose service name, commonly db |
Network location of the MySQL server |
WORDPRESS_DB_NAME |
MYSQL_DATABASE |
Database schema WordPress selects |
WORDPRESS_DB_USER |
MYSQL_USER |
Non-root MySQL account used by WordPress |
WORDPRESS_DB_PASSWORD |
MYSQL_PASSWORD |
Password for that account |
Names are case-sensitive where the underlying system treats them as such. Check the rendered configuration rather than assuming that a value in a .env file was loaded:
docker compose config
This command shows the Compose model after interpolation. Review it for an empty variable, an unintended quote, a typo in db, or a password containing characters that were interpreted by the shell or YAML.
Windows Errors? Fix Them Before They Spread
Repair common Windows errors and clear accumulated junk for a smoother, more stable PC - no reinstall needed.Free scan · no reinstallOutdated Drivers Are Slowing You Down
One free scan finds every outdated or missing driver and matches the right update for your exact hardware.Free scan · exact hardware matchThe database must already exist
WORDPRESS_DB_NAME is the database WordPress will use; the WordPress container does not create that database on the MySQL server. A new MySQL data directory can create the schema and user from MYSQL_DATABASE, MYSQL_USER, and MYSQL_PASSWORD during first initialization. If you point WordPress at a different name, create that database and grant the user access yourself, or change the WordPress value to the existing name.
Changing an environment variable after MySQL has already initialized its data directory does not reliably change the existing database, user, or password. The image’s initialization scripts are intended for an empty data directory. Inspect the live server instead of assuming that an edited Compose file migrated old data:
docker compose exec db mysql -uroot -p -e 'SHOW DATABASES;'
docker compose exec db mysql -uroot -p -e "SELECT User,Host FROM mysql.user;"
Use the root password that was configured for this installation; do not place a production password directly in shell history or in a published Compose file.
Account for MySQL’s asynchronous initialization
Starting the MySQL container means that its initialization process has begun, not that the server is already accepting application connections. On a new volume, MySQL creates system tables, applies initialization variables and scripts, and only then begins listening for clients. WordPress can therefore start first and report a connection refusal even though MySQL will become healthy moments later.
Rank #3
- [Low Noise High Fidelity] New bee guitar cord with 22AWG oxygen-free-copper center conductors provides enhanced signal transfer, the PVC insulation material and the high-density stranded copper double shield provide noise rejection for quiet operation
- [Ideal for Choice] New bee 1/4 straight and right angle metal connectors, ensures a secure connection in any instrument, pedal, or amp jack. L shape great fro on stage guitar stands
- [Wide Compatible] Suitable for mixer, power amplifier, microphone, effector, decoder, equalizer, electoronic organ, electric guitar, electric bass and other electronic equipments. Widely used in the installation of smart home, karaoke speaker, professional stage audio, etc
- [Easy Disassemble] Making incidental repairs quick and easy! Very nice, flexible cable
- [Dont Hesite to Order] 24 hours customer services and professional technology team are standing by
Watch initialization finish
docker compose logs -f db
Keep the project running while the log shows initialization. If WordPress exits once and the stack has no retry mechanism, start it again after MySQL reports that it is ready:
docker compose up -d db
docker compose up -d wordpress
Do not treat a transient refusal during first boot as proof that credentials are wrong. The definitive distinction is in the MySQL log: initialization messages indicate a startup race; authentication or unknown-database messages indicate configuration or data-state problems.
Add a health check and startup coordination
A health check gives Compose a testable readiness signal. In the example below, WordPress is created only after MySQL reports healthy. This prevents the most common first-boot race, although the application should still tolerate a later database restart.
services:
db:
image: mysql:8.0
environment:
MYSQL_DATABASE: wordpress
MYSQL_USER: wordpress
MYSQL_PASSWORD: ${MYSQL_PASSWORD:?set MYSQL_PASSWORD}
MYSQL_ROOT_PASSWORD: ${MYSQL_ROOT_PASSWORD:?set MYSQL_ROOT_PASSWORD}
volumes:
- db_data:/var/lib/mysql
healthcheck:
test: ["CMD-SHELL", "mysqladmin ping -h localhost -u root -p$${MYSQL_ROOT_PASSWORD} || exit 1"]
interval: 5s
timeout: 5s
retries: 20
start_period: 20s
wordpress:
image: wordpress:6-apache
depends_on:
db:
condition: service_healthy
environment:
WORDPRESS_DB_HOST: db:3306
WORDPRESS_DB_NAME: wordpress
WORDPRESS_DB_USER: wordpress
WORDPRESS_DB_PASSWORD: ${MYSQL_PASSWORD:?set MYSQL_PASSWORD}
volumes:
- wordpress_data:/var/www/html
volumes:
db_data:
wordpress_data:
Compose implementations differ in which depends_on conditions they support, so verify the behavior of the Compose version installed on your host. When a condition is unavailable, use a retry loop in the application or an entrypoint wrapper that waits for a successful database connection. The MySQL image documentation specifically notes that a connect-retry loop may be necessary when an application does not gracefully wait for MySQL downtime or startup.
Protect the data with persistent volumes
Container filesystems are disposable. Recreating a MySQL container without a persistent mount can produce an empty data directory, so the database that existed in the previous container is no longer available. Recreating WordPress without a persistent mount can remove themes, plugins, uploads, and the generated configuration.
| Data | Required mount | What is lost without it |
|---|---|---|
| MySQL data files | Named volume at /var/lib/mysql |
Databases, users, tables, and all stored content when the container is replaced |
| WordPress application files | Named volume at /var/www/html |
Uploads, plugins, themes, and WordPress files created or modified at runtime |
List the volumes and confirm that the expected ones are attached:
docker volume ls
docker inspect CONTAINER --format '{{json .Mounts}}'
Never remove a volume during diagnosis unless intentional data destruction is acceptable and you have a verified backup. A backup should be tested by restoring it, and a database backup should be made in a MySQL-consistent way rather than by copying files from a live server without a recovery plan.
Rank #4
- Digital Family Calendar: BSIMB digital calendar wall touch screen puts an end to your chaotic life. Designed for busy families, the digital calendar keeps you organised and in step with your family. Assign different colours and tasks to each family member to make family scheduling easier and more intuitive.
- Easy Setup and Auto-Sync: Plug in, connect to WLAN and auto-syn your electric calendar in minutes. Digital wall calendar compatible with Google calendar, iCloud calendar, Outlook calendar, Cozi calendar and Yahoo calendar. Add events directly on the device or through the ecalendar app. Electronic calendar stays current whether you're at work or traveling—no manual updates needed.
- All-In-One Home Assistant: Smart calendar builds habits and encourage independence with personalised chores. Display daily meal plan to reduce the daily ‘What's for dinner?’ stress. To-do lists keep track of everything you want. Turning chores into valuable achievements with stars and rewards, making life easier and more enjoyable.
- Manage Anytime Anywhere: BSIMB electronic calendar for family stay connected with the powerful ecalendar app. Access and manage your digital wall calendar anytime, anywhere with free features like stars & rewards, photo screensaver, chore charts, meals plans, to-do lists etc. Electronic planner paid features like Magic Import tailor advanced tools for users with special needs.
- Stay in Touch with Loved Ones: Share photos or videos from your phone to electronic wall calendar with app, instantly update your life moment, and keep in touch with your family, especially those who are far away; you can also surprise your smart calendar digital wall by sending him a wish card; it's also great for keeping tech-illiterate elders in touch with the youngsters.
Match the symptom to the underlying cause
“Error establishing a database connection” in WordPress
- Confirm that
WORDPRESS_DB_HOSTis the Compose service name, normallydb, notlocalhost. - Compare the database name, user, and password with the values that actually exist in MySQL.
- Check whether MySQL is still initializing or is repeatedly exiting.
- Verify that both services share a network and that the MySQL port is listening inside that network.
A browser error is only the application-level symptom. The database and WordPress logs identify whether the cause is refusal, authentication, name resolution, or a missing schema.
Do these 3 things before closing this tab:
1Clear out junk files and repair common Windows errors2Fix the driver behind crashes, sound loss and screen glitches3Repair Windows errors before they cause bigger problemsMySQL exits immediately
Read the first MySQL fatal line. A malformed command, an invalid option, an unreadable mounted directory, incompatible files in /var/lib/mysql, or a permission problem requires a different fix from a temporary readiness delay. If the data directory contains an existing installation, changing MYSQL_DATABASE or MYSQL_PASSWORD will not re-run first-boot initialization. Preserve the volume, verify its contents and ownership, and repair the actual account or database rather than deleting data to make the container start.
WordPress exits after a custom change
Temporarily remove custom commands, entrypoints, bind mounts, and added environment variables, then run the unmodified image with the persistent volumes still identified. If the image starts, reintroduce one change at a time. A missing executable, a script with Windows line endings, a non-executable file, or a path that exists on the host but not in the container can terminate the main process before the web server starts. The first fatal line usually names the failing path or command.
The container is killed under load
An out-of-memory kill is a resource problem, not a database-hostname problem. Confirm the state in docker inspect and check the host or virtual machine’s memory metrics. Reduce concurrent workload, investigate an unexpectedly large process, or allocate more memory to the Docker engine before relying on automatic restarts. A restart loop can repeatedly consume startup resources without curing the limit that caused the kill.
The container exits with code zero
A zero exit code usually means the configured command completed successfully. This is expected for a migration, backup, import, or command-line job designed to run once. Such a job should be invoked explicitly or from a scheduler; adding restart: always turns a successful one-shot completion into a pointless loop.
What’s actually slowing this PC down?
Pick the symptom - the matching free tool is one click away.
Use a complete, reproducible Compose configuration
The following pattern keeps the database and WordPress data, aligns the connection variables, waits for database health, and restarts long-running services after an unexpected crash. Pin image tags that you have tested rather than silently accepting an image change during a later pull. The password values are supplied through an environment file or secret mechanism, not copied into source control.
services:
db:
image: mysql:8.0
restart: always
environment:
MYSQL_DATABASE: wordpress
MYSQL_USER: wordpress
MYSQL_PASSWORD: ${MYSQL_PASSWORD:?set MYSQL_PASSWORD}
MYSQL_ROOT_PASSWORD: ${MYSQL_ROOT_PASSWORD:?set MYSQL_ROOT_PASSWORD}
volumes:
- db_data:/var/lib/mysql
healthcheck:
test: ["CMD-SHELL", "mysqladmin ping -h localhost -u root -p$${MYSQL_ROOT_PASSWORD} || exit 1"]
interval: 5s
timeout: 5s
retries: 20
start_period: 20s
wordpress:
image: wordpress:6-apache
restart: always
depends_on:
db:
condition: service_healthy
ports:
- "8080:80"
environment:
WORDPRESS_DB_HOST: db:3306
WORDPRESS_DB_NAME: wordpress
WORDPRESS_DB_USER: wordpress
WORDPRESS_DB_PASSWORD: ${MYSQL_PASSWORD:?set MYSQL_PASSWORD}
volumes:
- wordpress_data:/var/www/html
volumes:
db_data:
wordpress_data:
Start it in the foreground the first time so that you can see initialization:
Best Value
docker compose up
After both services are healthy, detach if desired:
docker compose up -d
docker compose ps
If your deployment already has data, do not switch image families, mount paths, or credentials casually. Back up first, verify the current database and user, and plan any image upgrade as a separate change.
Choose a restart policy only after the cause is fixed
A restart policy improves recovery from a transient crash or a host reboot; it does not create a database, correct a password, repair corrupted files, or make an invalid entrypoint executable. The documented Compose distinction is important: The
It will not create a missing container or apply a corrected Compose definition.docker compose start command is useful only to restart containers that were previously created but were stopped.
| Situation | Suitable approach | Reason |
|---|---|---|
| Long-running WordPress and MySQL services that should return after a crash or reboot | restart: always |
Restarts the service, but still leaves a visible loop when the underlying error persists |
| Development service that should stop when you intentionally stop it | A less aggressive policy or no policy | Prevents an intentional stop from being immediately undone |
| Migration, import, backup, or CLI task | No automatic restart | Normal completion is an exit, not a failure |
When a policy is already causing rapid restarts, temporarily remove it or stop the service, capture the logs, correct the configuration, and then restore the policy. The goal is an observable healthy service, not a container that merely remains in an opaque restart cycle.
Recovery playbooks
Credentials or database name were edited after first initialization
- Stop WordPress so it cannot continue making failed connection attempts:
docker compose stop wordpress. - Keep the MySQL volume. Do not run
docker compose down -v. - Inspect the existing schemas and users with MySQL administrative access.
- Either change WordPress back to the existing values or create and grant the intended database and user on the live server.
- Start WordPress and watch its logs while testing the connection.
MySQL is still initializing on a new volume
- Run
docker compose logs -f dband wait for the initialization sequence to finish. - Confirm that the health check eventually becomes healthy.
- Start or recreate WordPress after readiness is reported.
- If startup ordering remains unreliable, retain the health check and add application-level connection retries.
A mount or entrypoint change broke startup
- Save the current Compose file and the exact log output.
- Remove only the newest custom command, entrypoint, or bind mount.
- Recreate the container without deleting named volumes.
- Reintroduce changes individually, checking permissions and paths inside the container with
docker compose exec.
The host ran out of memory
- Confirm the out-of-memory indication in
docker inspectand host metrics. - Reduce concurrent jobs or memory-hungry plugins and processes.
- Increase the memory assigned to the Docker engine or virtual machine if appropriate.
- Only then rely on a restart policy for future transient crashes.
Self-hosted Compose or managed WordPress?
If repeated container maintenance is the real problem, compare the operational responsibilities rather than looking only at the monthly price. A managed service can remove some Docker work, while self-hosting preserves control over images and networks.
| Decision axis | Self-hosted Compose | Managed WordPress or VPS service |
|---|---|---|
| Control | You choose Compose files, image tags, networks, and upgrade timing. | The provider controls more of the platform and may restrict image or network choices. |
| Persistence and backups | You must maintain named volumes, tested backups, and restore procedures. | Backups may be integrated, but retention, restore scope, and pricing must be verified. |
| Startup health and retries | You configure health checks, dependency ordering, and application retries. | The platform may supply readiness automation, subject to its documented limits. |
| Observability | You have direct access to Compose status, container logs, and host metrics. | You rely on the provider’s log retention, alerts, and support interfaces. |
| Upgrades | You test image, PHP, MySQL, and plugin changes and coordinate migrations. | Some upgrades are operated for you, but timing and compatibility may be less controllable. |
| Total operating cost | Infrastructure may be inexpensive while your time, backups, monitoring, and incident recovery remain your responsibility. | A higher bill can trade for less hands-on maintenance; compare included resources and backup guarantees. |
Whichever model you choose, the same fundamentals apply: the application must reach the database by its service name, the credentials must match an existing account, readiness must be handled explicitly, and data must be backed up independently of container recreation.
Recommended Free Tools
Quick Recap
Final verification checklist
docker compose ps -ashows both services running, and the database health check is healthy when one is configured.- The first fatal log line has been addressed rather than hidden by repeated restarts.
WORDPRESS_DB_HOSTuses the Compose database service name, notlocalhost.- The WordPress database name, user, and password match the account and schema that actually exist in MySQL.
- The MySQL initialization sequence has completed before WordPress is expected to connect.
/var/lib/mysqland/var/www/htmlare backed by the intended named volumes or equivalent persistent mounts.- No diagnostic step removed a volume without an intentional, verified backup.
- Restart policies are applied only to services intended to run continuously.
- Image tags, secrets, health checks, and backup restores are documented for the next rebuild.
Product prices and availability are accurate as of the date/time indicated and are subject to change. Any price and availability information displayed on Amazon at the time of purchase will apply.




