[Docker] How to resolve Error response from daemon: Container xxx is restarting, wait until the container is running
I’ll introduce how to resolve the Docker error “Error response from daemon: Container xxx is restarting, wait until the container is running”.
This is a story about running Mastodon on Linode VPS, encountering physical hardware failure, and after troubleshooting, the docker container running the application started throwing errors and wouldn’t start.
$ sudo docker exec -it mastodon_web_1 /bin/sh
Error response from daemon: Container e398061d59d6cb20f3cdbbf4013e9e6e8080b8c1afc59d7b06b7d8c3f0dd1d47 is restarting, wait until the container is running
First, I tried to enter the mastodon_web_1 shell but couldn’t.
$ docker ps
CONTAINER ID IMAGE COMMAND CREATED STATUS PORTS NAMES
45ebb1c8ef61 gargron/mastodon "npm run start" 2 days ago Up 4 minutes 3000/tcp, 0.0.0.0:4000->4000/tcp mastodon_streaming_1
9d8bd45c983c gargron/mastodon "bundle exec sidek..." 2 days ago Up 4 minutes 3000/tcp, 4000/tcp mastodon_sidekiq_1
e398061d59d6 gargron/mastodon "bundle exec rails..." 2 days ago Restarting (1) 18 seconds ago mastodon_web_1
53e10f7f14d4 postgres:alpine "docker-entrypoint..." 3 days ago Up 4 minutes 5432/tcp mastodon_db_1
04f51c868073 redis:alpine "docker-entrypoint..." 3 days ago Up 4 minutes 6379/tcp mastodon_redis_1
When I checked the container status with docker ps, it seemed to be stuck in Restarting (1) status and wouldn’t start.
$ docker logs e398061d59d6
A server is already running. Check /mastodon/tmp/pids/server.pid.
=> Booting Puma
=> Rails 5.0.2 application starting in production on http://0.0.0.0:3000
=> Run `rails server -h` for more startup options
Exiting
When I checked the logs with the docker logs command, I found it was failing at puma server process startup.
$ docker rm mastodon_web_1
mastodon_web_1
Since mastodon_web_1 is an application container, I deleted mastodon_web_1 with the docker rm command. If this were a database container, I couldn’t delete it with docker rm, so I’d need to consider other approaches.
$ docker ps
CONTAINER ID IMAGE COMMAND CREATED STATUS PORTS NAMES
45ebb1c8ef61 gargron/mastodon "npm run start" 2 days ago Up 19 minutes 3000/tcp, 0.0.0.0:4000->4000/tcp mastodon_streaming_1
9d8bd45c983c gargron/mastodon "bundle exec sidek..." 2 days ago Up 19 minutes 3000/tcp, 4000/tcp mastodon_sidekiq_1
53e10f7f14d4 postgres:alpine "docker-entrypoint..." 3 days ago Up 19 minutes 5432/tcp mastodon_db_1
04f51c868073 redis:alpine "docker-entrypoint..." 3 days ago Up 19 minutes 6379/tcp mastodon_redis_1
I confirmed with docker ps that mastodon_web_1 is gone.
$ sudo docker-compose stop
Stopping mastodon_streaming_1 ... done
Stopping mastodon_sidekiq_1 ... done
Stopping mastodon_db_1 ... done
Stopping mastodon_redis_1 ... done
I stopped all containers with docker-compose stop and then started the containers with docker-compose up -d.
$ sudo docker-compose up -d
Starting mastodon_redis_1
Starting mastodon_db_1
Starting mastodon_streaming_1
Starting mastodon_sidekiq_1
Creating mastodon_web_1
At this point, since mastodon_web_1 doesn’t exist, a new container is created.
$ docker ps
CONTAINER ID IMAGE COMMAND CREATED STATUS PORTS NAMES
20ce27549e01 gargron/mastodon "bundle exec rails..." 5 minutes ago Up 5 minutes 0.0.0.0:3000->3000/tcp, 4000/tcp mastodon_web_1
45ebb1c8ef61 gargron/mastodon "npm run start" 2 days ago Up 5 minutes 3000/tcp, 0.0.0.0:4000->4000/tcp mastodon_streaming_1
9d8bd45c983c gargron/mastodon "bundle exec sidek..." 2 days ago Up 5 minutes 3000/tcp, 4000/tcp mastodon_sidekiq_1
53e10f7f14d4 postgres:alpine "docker-entrypoint..." 3 days ago Up 5 minutes 5432/tcp mastodon_db_1
04f51c868073 redis:alpine "docker-entrypoint..." 3 days ago Up 5 minutes 6379/tcp mastodon_redis_1
With docker ps, I could confirm that mastodon_web_1 is successfully running.
I hope this helps those who are using Docker for the first time with Mastodon and suddenly need to handle such situations.
That’s all from the Gemba.