How to deploy and manage containerized Linux systems
With the rise of cloud computing and microservice architecture, containerization technology has become an important part of software development and deployment tool. Containerized deployment and management solutions on Linux systems, such as Docker and Kubernetes, have been widely adopted. This article will introduce how to use Docker for container deployment and management, and give specific code examples.
First, you need to install Docker on the Linux system. You can install Docker through the following command:
$ sudo apt-get update $ sudo apt-get install docker.io
After the installation is complete, you can use the following command to verify whether Docker is installed successfully:
$ docker --version
Docker image is a template used to create Docker containers. The content and configuration of the image can be defined through Dockerfile. The following is a simple Dockerfile example:
# 使用基础镜像 FROM ubuntu:16.04 # 安装所需软件包 RUN apt-get update && apt-get install -y nginx php7.2 mysql-server # 复制配置文件到镜像中 COPY nginx.conf /etc/nginx/nginx.conf COPY index.php /var/www/html/index.php # 容器启动时运行的命令 CMD ["nginx", "-g", "daemon off;"]
In the above example, a base image ubuntu:16.04
is first used, then several software packages are installed, and the configuration files and applications are copied. The program code finally sets the command to run when the container starts.
The command to build the image is docker build
, which is done by specifying the directory and Dockerfile path. For example, run the following command in the current directory:
$ docker build -t myapp .
The above command will build an image named myapp
.
Next, you can use the following command to run the image to create the container:
$ docker run -d -p 80:80 myapp
In the above command, the parameter -d
means running in background mode, -p 80 :80
means mapping port 80 of the host to port 80 of the container.
Manage containers through Docker commands. Here are some commonly used command examples:
$ docker ps
$ docker ps -a
$ docker stop <容器ID>
$ docker start <容器ID>
$ docker exec -it <容器ID> /bin/bash
$ docker rm <容器ID>
$ docker logs <容器ID>
The above are just some common ones Command examples, Docker also provides many other functions and commands that can be learned and used according to specific needs.
Summary:
This article introduces how to use Docker for containerized deployment and management of Linux systems, and gives specific code examples. By learning and mastering this knowledge, software development and deployment can be carried out more effectively, and work efficiency and system stability can be improved. Hope this article is helpful to readers.
The above is the detailed content of How to deploy and manage containerized Linux systems. For more information, please follow other related articles on the PHP Chinese website!