Setting Up the Base Environment
Begin by retrieving the latest Ubuntu image from Docker Hub:
docker pull ubuntu:latest
Confirm the image is available locally:
docker images | grep ubuntu
Initialzie a new container in detached mode with interactive terminal support:
docker run -d -it --name dev_ubuntu ubuntu:latest /bin/bash
Access the running container's shell:
docker exec -it dev_ubuntu bash
System Configuration and Package Installation
Update the package index and upgrade existing packages:
apt-get update -y && apt-get upgrade -y
Configure the system timezone non-interactively:
apt-get install -y tzdata
echo "Asia/Shanghai" > /etc/timezone
dpkg-reconfigure -f noninteractive tzdata
Install network diagnostic utilities:
apt-get install -y net-tools iputils-ping
Add a text editer for configuration tasks:
apt-get install -y vim
Install and enable SSH server for remote access:
apt-get install -y openssh-server
Verify the SSH daemon status:
systemctl status ssh || service ssh status
Modify SSH configuration to permit root login and password authentication:
sed -i 's/#PermitRootLogin prohibit-password/PermitRootLogin yes/' /etc/ssh/sshd_config
sed -i 's/#PasswordAuthentication yes/PasswordAuthentication yes/' /etc/ssh/sshd_config
Restart the SSH service to apply changes:
service ssh restart
Creating a Validation Script
Generate a test script to verify environment functionality:
cat > /usr/local/bin/validate.sh << 'EOF'
#!/bin/bash
echo -e "\033[1;32m Container customization complete \033[0m"
EOF
chmod +x /usr/local/bin/validate.sh
Execute the validation script:
/usr/local/bin/validate.sh
Exit the container:
exit
Persisting and Exporting the Container
Stop the container before creating an image:
docker stop dev_ubuntu
Commit the container to a new image with proper tagging:
docker commit dev_ubuntu myubuntu:custom-v1
Verify the image creation:
docker images | grep myubuntu
Export the image to a portable tarball:
docker save -o ubuntu-custom-image.tar myubuntu:custom-v1
The tarball ubuntu-custom-image.tar now contains your configured Ubuntu environment ready for distribution or backup.