Cloud Native 5 min read

Using Docker to Build and Manage a CentOS 7 Linux Virtual Machine

This tutorial explains how to download a CentOS 7 Docker image, run it as a lightweight Linux virtual machine, map ports and directories, access the container's shell, and export or import the container as an image for easy migration across hosts.

360 Quality & Efficiency
360 Quality & Efficiency
360 Quality & Efficiency
Using Docker to Build and Manage a CentOS 7 Linux Virtual Machine

Docker is an open‑source container engine written in Go that provides process‑level sandboxing with minimal performance overhead, allowing multiple containers to share the same CPU and memory resources.

The article demonstrates how to use Docker to create a Linux virtual machine based on a CentOS 7 image, covering image download, container startup, port and volume mapping, image export, and import for environment migration.

Download Image

CentOS image repository: https://hub.docker.com/_/centos?tab=tags&page=1

Command to pull the image:

docker pull centos:7

After pulling, verify with docker images to see the docker.io/centos entry.

Run Container

Start a container from the downloaded image:

docker run -itd --name centos-test -p 4749:4749 -v /data/test/www:/data/www docker.io/centos:7 /sbin/init

Use docker ps -a to confirm the container (e.g., centos-test ) is running.

Enter Container

To access the running container’s shell:

docker exec -it centos7-test /bin/bash

This opens an interactive Bash session inside the CentOS 7 environment.

Export Container as Image

Export the container’s filesystem to a tar archive for migration:

docker export -o centos7-back.tar d4480dc94cdd

The resulting centos7-back.tar file contains the exported image.

Import Image

Import the tar archive back into Docker as a new image:

cat centos7-back.tar | docker import - centos7-back.tar

Verify the new image with docker images ; the imported image appears as centos7-back.tar .

Conclusion

Compared with traditional VMs (e.g., Vagrant, VMware) that partition hardware resources, Docker containers are lightweight, share host resources efficiently, and simplify environment replication across hosts.

DockerLinuxContainerVirtual MachineCentOSimage exportimage import
360 Quality & Efficiency
Written by

360 Quality & Efficiency

360 Quality & Efficiency focuses on seamlessly integrating quality and efficiency in R&D, sharing 360’s internal best practices with industry peers to foster collaboration among Chinese enterprises and drive greater efficiency value.

0 followers
Reader feedback

How this landed with the community

login Sign in to like

Rate this article

Was this worth your time?

Sign in to rate
Discussion

0 Comments

Thoughtful readers leave field notes, pushback, and hard-won operational detail here.