Network Security Internet Technology Development Database Servers Mobile Phone Android Software Apple Software Computer Software News IT Information

In addition to Weibo, there is also WeChat

Please pay attention

WeChat public account

Shulou

How to run the Docker container on CentOS or Fedora

2025-04-02 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Servers >

Share

Shulou(Shulou.com)06/01 Report--

This article mainly explains "how to run Docker container on CentOS or Fedora". The content of the article is simple and clear, and it is easy to learn and understand. Please follow the editor's train of thought to study and learn "how to run Docker container on CentOS or Fedora".

Recently, Docker has demonstrated a key technology for deploying applications in the cloud. Compared with traditional hardware virtualization, the sandbox based on Docker container provides a series of advantages for application deployment environment, such as lightweight isolation, easy deployment, easy maintenance and so on. Red Hat now provides community support for Docker container management and deployment.

Not only in the cloud environment, Docker is also useful for end users, especially if you want to try popular software in a specified linux container. You can easily launch the Docker container for the target environment, install and test the software in the container, and then discard the container after your testing is complete. The whole process from start to finish is very efficient. You can avoid the trouble of messing up your system environment from beginning to end.

In this tutorial, I will describe how to create and manage Docker containers on CentOS and Fedora. Note that Docker only supports 64-bit operating systems. If you want to test based on Ubuntu, please refer to this tutorial

Install the Docker container on CentOS or Fedora

To install Docker on CentOS, you first need to add the EPEL repository, then use the yum command:

$sudo yum install docker-io$ sudo service docker start$ sudo chkconfig docker on

Install Docker on Fedora, using the following command:

$sudo yum install docker-io$ sudo systemctl start docker.service$ sudo systemctl enable docker.service

After installing Docker on CentOS or Fedora, in order to run docker as a non-root user, you need to add yourself to the docker user group, using the following command:

Sudo usermod-a-G docker $USER

Log out, and then log in again for the group changes to take effect.

At this point, you should be able to run the docker command as an unprivileged user.

Basic usage of Docker

To launch a new Docker container, you need to decide which Docker image to use by searching the official Docker image index, which lists publicly available Docker images. This Docker index contains linux basic images managed by Docker team (such as Ubuntu, Debian, Fedora, CentOS), as well as normal images contributed by users (such as MySQL, Redis, WordPress).

For example, start a Ubuntu container in interactive mode and run the following command, and the last parameter,'/ bin/bash', is the command used to execute inside the container.

$docker run-I-t ubuntu / bin/bash

The first time we run the above command, it will download the Docker image of the available Ubuntu through the network, and use this image to start a Docker container, a Ubuntu container will start immediately, you will see the console prompt in the container, you can access a full-fledged Ubuntu operating system through the container sandbox.

If you type exit at the prompt, you will exit from the container and the container will be stopped.

Get a list of all containers (including stopped) and run the following command:

$docker ps-a

CONTAINER ID IMAGE COMMAND CREATED STATUS PORTS NAMES

6a08a0b2bb4c ubuntu:14.04 / bin/bash About a minute ago Exit 0 cocky_ritchie

Restart a stopped container in the background:

$docker start [container-id]

Remove a container that has stopped:

$docker rm [container-id]

To view or interact with a container, enter a container that runs in the background

$docker attach [container-id]

You are free to customize a running container (for example, to install new software). If you want to save changes to the current container, first type the command ``exit``` to exit interactive mode, and then use this command to save the image of the change. save it as a new and different image.

$docker commit [container-id] [new-image-name]

Get the container ID of your container. You can use ```docker ps-a``` to view it.

Once you create a new image like this, you can use it to run a new container.

You can also download any public images (such as ubuntu, bowery/mysql) and store them in the local repository, as follows.

$docker pull [image name]

View all local images that have been downloaded or saved:

$docker images

You can select a specified image to start a container:

$docker run-I-t [image-id] / bin/bash

Delete an image from the local repository:

$docker rmi [image-id]

Thank you for your reading, the above is the content of "how to run Docker container on CentOS or Fedora". After the study of this article, I believe you have a deeper understanding of how to run Docker container on CentOS or Fedora, and the specific use needs to be verified in practice. Here is, the editor will push for you more related knowledge points of the article, welcome to follow!

Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.

Views: 0

*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.

Share To

Servers

Wechat

© 2024 shulou.com SLNews company. All rights reserved.

12
Report