When working with Docker containers, you might encounter the frustrating "Error response from daemon: No command specified
" message after importing a previously exported container. Here's what's happening under the hood:
# Original working container
docker run --name u1 -dit ubuntu:latest
# Export/import flow that fails
docker export -o exported u1
docker import exported ubuntu:imported
docker run --name u2 -dit ubuntu:imported # Fails here
The key difference between docker export
and docker commit
is that export
only saves the filesystem, while commit
preserves the container configuration including the default command. The Ubuntu base image specifies /bin/bash
as its default command, but this metadata gets lost during export/import.
Solution 1: Specify the command explicitly
docker run --name u2 -dit ubuntu:imported /bin/bash
Solution 2: Use docker commit instead (preserves configuration)
docker commit u1 ubuntu:committed
docker run --name u2 -dit ubuntu:committed
Solution 3: Create a new image with proper CMD
# Dockerfile
FROM scratch
ADD exported /
CMD ["/bin/bash"]
# Build command
docker build -t ubuntu:rebuilt .
For temporary containers where you just need shell access, Solution 1 is simplest. For preserving complex container states, Solution 2 works best. When you need to rebuild the image with proper metadata (like for distribution), Solution 3 is most appropriate.
If your original container had custom entrypoints, you can inspect them before export:
docker inspect --format='{{.Config.Cmd}}' u1
docker inspect --format='{{.Config.Entrypoint}}' u1
Then recreate them during import using Solution 3's Dockerfile approach by adding:
ENTRYPOINT ["/your/entrypoint"]
CMD ["your", "command"]
The error occurs during container migration when using docker export/import
workflow. Unlike docker commit
which preserves metadata, the export/import process strips critical configuration including:
1. CMD/ENTRYPOINT instructions
2. ENV variables
3. Working directory settings
4. Exposed ports configuration
Here's a complete test case showing both the problem and solution:
# Original container setup
docker run -dit --name test_container ubuntu:22.04 bash
docker export test_container > exported_container.tar
# Problematic import
docker import exported_container.tar imported:broken
docker run -dit imported:broken
# Throws: Error response from daemon: No command specified
Method 1: Rebuild with Dockerfile
FROM scratch
ADD exported_container.tar /
CMD ["/bin/bash"] # Or your original entrypoint
Method 2: Single-command import
cat exported_container.tar | docker import \
--change "CMD /bin/bash" \
- imported:working
For production migrations, consider these alternatives:
# Option 1: Save full container state
docker commit test_container working_image
# Option 2: Use docker save/load
docker save ubuntu:22.04 > image.tar
docker load < image.tar
When you must use export/import, preserve config separately:
# Get original config
docker inspect test_container > config.json
# Apply during import
docker import --change "$(jq '.[0].Config' config.json)" \
exported_container.tar configured_image
Remember that exported containers lose:
- Volume definitions
- Network settings
- Healthcheck configurations