Exit Code 143
DockerINFOShutdownHIGH confidence

Graceful shutdown via SIGTERM

What this means

Exit code 143 (128 + 15 for SIGTERM) signifies that the container was terminated gracefully. When you run 'docker stop' or 'docker-compose down', Docker first sends a SIGTERM signal to the main process (PID 1) inside the container, giving it a chance to shut down cleanly. If the process exits upon receiving this signal, its exit code will be 143.

Why it happens
  1. 1Running 'docker stop <container>' command.
  2. 2Running 'docker-compose down' or 'docker-compose stop'.
  3. 3The orchestrator (like Kubernetes or Swarm) is stopping the container as part of a deployment or scaling operation.
  4. 4The container's process correctly handled the SIGTERM signal and exited.
How to reproduce

A user manually stops a running Nginx container.

trigger — this will error
trigger — this will error
# Start a container in the background
docker run -d --name webserver nginx
# Stop the container
docker stop webserver
# Check its exit code
docker wait webserver

expected output

143

Fix 1

Implement a Signal Handler

WHEN Your application needs to perform cleanup tasks (e.g., close database connections, save state) before exiting.

Implement a Signal Handler
# Example in a Node.js application
process.on('SIGTERM', () => {
  console.log('SIGTERM signal received. Closing http server.');
  server.close(() => {
    console.log('Http server closed.');
    process.exit(0); // Exit with 0 to indicate success
  });
});

Why this works

By trapping the SIGTERM signal, the application can execute custom logic to shut down gracefully instead of being abruptly terminated.

Fix 2

Adjust the Stop Grace Period

WHEN Your application needs more (or less) time to shut down than the default 10 seconds.

Adjust the Stop Grace Period
# Using docker stop with a 30-second grace period
docker stop --time=30 my-container

# In docker-compose.yml
services:
  myapp:
    image: myapp
    stop_grace_period: 30s

Why this works

This overrides the default timeout, giving the application more time to finish its cleanup process before Docker sends a forceful SIGKILL.

What not to do

Treat Exit Code 143 as an error.

It is the expected and desired outcome for a graceful shutdown initiated by Docker. Alerting on this code will lead to false positives.

Sources

Content generated with AI assistance and reviewed for accuracy. Found an error? hello@errcodes.dev

← All Docker errors