The 'Container already running' error occurs when you try to start a Docker container that is already in a running state. Use docker exec to access the running container, or stop it first if you need to restart it.
The "Error response from daemon: Container already running" message appears when you attempt to use `docker start` on a container that is currently in a running state. Docker prevents this action because starting an already-running container doesn't make sense and could indicate a misunderstanding of the container's current state. This error is fundamentally different from the "container name already in use" error. Here, the container exists and is actively running, so Docker correctly refuses to "start" it again. The daemon is telling you that your intended action is already satisfied—the container is running. This commonly happens in scripts or CI/CD pipelines where the same `docker start` command is executed multiple times, or when developers forget that a container is already running in the background.
First, verify the container's state to confirm it's already running:
# List running containers
docker ps
# Check specific container status
docker ps --filter "name=mycontainer"
# Get detailed container state
docker inspect --format='{{.State.Status}}' mycontainerIf the container shows as "running" or "Up", then the docker start command isn't needed—the container is already active.
If you need to run commands inside the container, use docker exec instead of trying to start it:
# Run a command in the running container
docker exec mycontainer ls -la
# Open an interactive shell
docker exec -it mycontainer /bin/bash
# Or use sh if bash isn't available
docker exec -it mycontainer /bin/sh
# Run as a specific user
docker exec -u root -it mycontainer /bin/bashThe docker exec command runs a new process inside an already-running container, which is typically what you want.
If you specifically need to restart the container (stop and start), use the docker restart command:
# Restart the container
docker restart mycontainer
# Restart with a custom timeout (seconds to wait before killing)
docker restart -t 30 mycontainer
# Restart multiple containers
docker restart container1 container2 container3This is equivalent to running docker stop followed by docker start, but in a single command.
If you need to stop the container first for some reason, then start it again:
# Stop the container gracefully
docker stop mycontainer
# Stop with a shorter timeout (default is 10 seconds)
docker stop -t 5 mycontainer
# Now you can start it
docker start mycontainerNote that stopping a container sends SIGTERM to the main process, allowing it to shut down gracefully. After the timeout, Docker sends SIGKILL.
In scripts, check if the container is running before attempting to start:
#!/bin/bash
CONTAINER_NAME="mycontainer"
# Check if container is running
if [ "$(docker ps -q -f name=$CONTAINER_NAME)" ]; then
echo "Container is already running"
else
echo "Starting container..."
docker start $CONTAINER_NAME
fiOr use a more robust approach that handles any state:
#!/bin/bash
CONTAINER_NAME="mycontainer"
# Get container state
STATE=$(docker inspect --format='{{.State.Status}}' $CONTAINER_NAME 2>/dev/null)
case "$STATE" in
running)
echo "Container is already running"
;;
exited|created)
echo "Starting container..."
docker start $CONTAINER_NAME
;;
*)
echo "Container not found or in unexpected state: $STATE"
;;
esacIf it's acceptable for the container to already be running, you can suppress the error:
# Ignore the error and continue
docker start mycontainer 2>/dev/null || true
# Or check exit code explicitly
docker start mycontainer 2>/dev/null
if [ $? -eq 0 ]; then
echo "Container started"
else
echo "Container may already be running or doesn't exist"
fiFor idempotent CI/CD pipelines, this approach ensures the step doesn't fail if the container is already running.
### Understanding Container States
Docker containers can be in several states:
- created: Container exists but has never been started
- running: Container is currently active
- paused: Container processes are paused
- restarting: Container is in the process of restarting
- exited: Container has stopped
- dead: Container failed to stop properly
The docker start command only works on containers that are not in the "running" state.
### Port Forwarding Behavior
Attempting to start an already-running container can sometimes affect port mappings. As noted in GitHub issue [moby/moby#2405](https://github.com/moby/moby/issues/2405), attempting to start a running container could historically cause forwarded ports to disappear from docker ps output. While this has been addressed, it's another reason to check container state before starting.
### Idempotent Container Management
For truly idempotent container startup in automation:
# Ensure container is running regardless of current state
docker start mycontainer 2>/dev/null || docker run -d --name mycontainer myimageThis pattern attempts to start an existing container, and if that fails (because it doesn't exist), creates a new one.
### Docker Compose Behavior
Docker Compose handles this scenario automatically. Running docker-compose up -d on already-running services does nothing (they keep running). It only starts services that aren't running:
# Start services (only starts those not already running)
docker-compose up -d
# Force recreation of running services
docker-compose up -d --force-recreate### Restart Policies and This Error
If a container has a restart policy like --restart=always, it may automatically restart after stopping. This can lead to the "already running" error if you try to start it immediately after stopping:
# Container with restart policy
docker run -d --restart=always --name myapp myimage
# Stopping it may trigger automatic restart
docker stop myapp
docker start myapp # May fail if restart policy already restarted itTo prevent this, remove the container or update the restart policy before stopping.
dockerfile parse error line 5: unknown instruction: RRUN
How to fix 'unknown instruction' Dockerfile parse error in Docker
Error response from daemon: manifest for nginx:nonexistent not found: manifest unknown: manifest unknown
How to fix 'manifest for image:tag not found' in Docker
Error response from daemon: invalid reference format: repository name must be lowercase
How to fix 'repository name must be lowercase' in Docker
Error response from daemon: No such image
How to fix 'No such image' in Docker
Error response from daemon: Container is not running
How to fix 'Container is not running' when using docker exec