This approach is useful for learning, debugging, or quick experimentation, though Dockerfiles are recommended for production.
Prerequisites
- Docker installed
- Ability to run
dockercommands - Basic shell knowledge
Check Docker:
docker version
Demo Scenario
We will build a custom image that:
- Uses Ubuntu
- Installs curl
- Adds a custom file
Step 1: Pull a Base Image
Start by pulling the base image.
docker pull ubuntu:22.04
Verify:
docker images
Step 2: Run an Interactive Container
Run the container in interactive mode:
docker run -it –name demo-container ubuntu:22.04 /bin/bash
Explanation:
-it→ interactive terminal--name→ easier reference later/bin/bash→ shell inside the container
You are now inside the container.
Step 3: Modify the Container (Install Software)
Update package lists:
apt update
Install curl:
apt install -y curl
Verify installation:
curl –version
Step 4: Add Custom Content
Create a custom file:
echo “Hello from a Docker image built without a Dockerfile!” > /message.txt
cat /message.txt
Step 5: Exit the Container
Shell
exit
Show more lines
The container is now stopped but still exists.
Check:
docker ps -a
Step 6: Commit the Container as an Image
Convert the container into an image:
docker commit demo-container demo-image:1.0
Explanation:
demo-container→ source containerdemo-image:1.0→ new image name and tag
Verify:
Shell
docker images
You now have a new image built without a Dockerfile.
Step 7: Run a Container from the New Image
docker run -it demo-image:1.0 /bin/bash
Inside the container:
curl –version
cat /message.txt
✅ Both should work, proving the image was built correctly.
Step 8 (Optional): Add Metadata During Commit
You can add metadata such as CMD, ENV, or labels:
docker commit \
–author “Your Name” \
–message “Installed curl and added message file” \
demo-container demo-image:2.0
Example with a default command:
docker commit \
–change=’CMD [“cat”, “/message.txt”]’ \
demo-container demo-image:3.0
Show more lines
Run it:
Shell
docker run demo-image:3.0
How This Differs from a Dockerfile
| Dockerfile | No Dockerfile |
|---|---|
| Declarative | Imperative |
| Reproducible | Manual |
| Version-controllable | Harder to track |
| Best practice | Learning / quick demos |
Cleanup (Optional)
Remove container:
docker rm demo-container
Remove image:
docker rmi demo-image:1.0
