Docker Tutorial
Docker Installation
How to use Docker
Docker Instance
Docker Container Lifecycle Command
Docker Container Operation Command
Docker Container rootfs Command
Docker Mirror Repository Command
Docker Local Image Management Command
Docker info|version Command
In this tutorial, you'll learn how to create a Docker container with CentOS, a popular Linux distribution. We'll use the official CentOS image provided by the Docker community.
Prerequisites:
Pull the official CentOS image:
To pull the official CentOS image, run the following command:
docker pull centos
This will download the latest version of the CentOS image to your system.
Create a new container with CentOS:
To create a new Docker container running CentOS, use the docker run
command. We'll run the container in interactive mode with a TTY attached to it:
docker run -it --name centos-container centos
This command creates a new container named centos-container
and starts a bash session inside the container. You should now see the container's command prompt.
Explore the CentOS container:
With the bash session running inside the container, you can explore the CentOS environment and run commands as you would on a regular CentOS system. For example, you can check the CentOS version by running:
cat /etc/centos-release
You can also update the system packages using yum
:
yum update -y
And install new packages:
yum install -y package_name
Replace package_name
with the name of the package you want to install.
Exit the CentOS container:
When you're done exploring the CentOS container, you can exit the bash session by typing exit
or pressing Ctrl+D
. This will stop the container.
Start the CentOS container again:
If you want to start the stopped CentOS container again, use the docker start
command followed by the docker attach
command:
docker start centos-container docker attach centos-container
This will start the centos-container
and attach your terminal to the running container, allowing you to interact with the container again.
In this tutorial, we covered how to create a Docker container with CentOS, interact with the container using a bash session, and manage the CentOS environment inside the container. You can now use this containerized CentOS environment for development, testing, or deployment purposes.
Running CentOS in Docker Container:
docker run -it --name my-centos-container centos:latest
How to Create a Docker Image with CentOS:
FROM centos:latest # Add custom configurations or packages
Docker-Compose CentOS Installation:
version: '3' services: centos: image: centos:latest
CentOS Dockerfile Example:
FROM centos:latest RUN yum install -y my-package
Setting Up CentOS in a Docker Environment:
version: '3' services: centos: image: centos:latest environment: - MY_VARIABLE=value
Configuring CentOS in Docker-Compose:
version: '3' services: centos: image: centos:latest volumes: - ./my-config:/etc/my-config
Docker CentOS Image Customization:
FROM centos:latest RUN yum install -y my-package
Docker CentOS Volume Mounts:
version: '3' services: centos: image: centos:latest volumes: - ./my-data:/data
Custom CentOS Image Creation in Docker:
FROM centos:latest RUN yum install -y my-package COPY my-config /etc/my-config
Docker Swarm and CentOS Service:
version: '3' services: centos: image: centos:latest deploy: replicas: 3 # Other Swarm deployment configurations
Troubleshooting CentOS in Docker:
docker logs <centos_container_id_or_name>