Home Operation and Maintenance Linux Operation and Maintenance How to build Docker on ECS in Linux operating system

How to build Docker on ECS in Linux operating system

Sep 19, 2018 am 11:32 AM
linux

This article introduces how to build Docker on ECS in the Linux operating system, and focuses on the specific steps. The content of this article is very compact, and I hope you will study patiently.

Building Docker on ECS (CentOS7)

This article describes the deployment process of Docker on the CentOS system. Regarding installing Docker under the Ubuntu system, please refer to the docker practice document for specific practices.

Applicable objects

Applicable to developers who are familiar with the Linux operating system and have just started using Alibaba Cloud ECS.

Main content

Deploy docker

Basic usage of docker

Image production

Deploy Docker

Main description of this article For manual installation of docker, you can also choose to purchase the corresponding image in the cloud market and deploy the cloud server with one click.

The practical operating system version of this article is CentOS 7.2 64 3.10.0-514.6.2.el7.x86_64.

Docker requires a 64-bit system and the kernel version is at least 3.10

Add the yum source.

# yum install epel-release –y
# yum clean all
# yum list
Copy after login

Install and run Docker.

# yum install docker-io –y
# systemctl start docker
Copy after login

Check the installation results.

# docker info
Copy after login

The following xin description information appears, indicating that the installation is successful.

How to build Docker on ECS in Linux operating system

Basic usage of Docker

Docker daemon management.

# systemctl start docker     #运行Docker守护进程
# systemctl stop docker      #停止Docker守护进程
# systemctl restart docker   #重启Docker守护进程
Copy after login

Image management. This article uses the Apache image from the Alibaba Cloud warehouse.

# docker pull registry.cn-hangzhou.aliyuncs.com/lxepoo/apache-php5
Copy after login

Modify the label. Since the image name of the Alibaba Cloud warehouse image is very long, you can modify the image label to facilitate memory distinction.

# docker tag  registry.cn-hangzhou.aliyuncs.com/lxepoo/apache-php5:latest aliweb:v1
Copy after login

View existing mirrors.

# docker images
Copy after login

Forced deletion of the image.

# docker  rmi  –f  registry.cn-hangzhou.aliyuncs.com/lxepoo/apache-php5
Copy after login

Container management.

e121d5f99e1e is the IMAGE ID queried by executing the docker images command. Use the docker run command to enter the container.

# docker run –ti e121d5f99e1e /bin/bash
Copy after login

Use exit to exit the current container.

The run command plus the -d parameter can run the container in the background. -name specifies that the container is named apache.

# docker run -d --name apache e121d5f99e1e
Copy after login

Enter the container running in the background.

# docker exec -ti apache /bin/bash
Copy after login

Make the container into a mirror.

# docker commit containerID/containerName  newImageName:tag
Copy after login

In order to facilitate testing and recovery, first run the source image and then make a simply named image for testing.

# docker commit 4c8066cd8c01 apachephp:v1
Copy after login

Run the container and map the 8080 port of the host to the container.

# docker run -d -p 8080:80 apachephp:v1
Copy after login

Enter the host IP and 8080 port in the browser to access the test. If the following content appears, it means the operation is successful.

How to build Docker on ECS in Linux operating system

Image production

Prepare the dockerfile content.

# vim Dockerfile 
FROM apachephp:v1  #声明基础镜像来源
MAINTAINER DTSTACK #声明镜像拥有者
RUN mkdir /dtstact #RUN后面接容器运行前需要执行的命令,由于Dockerfile文件不能超过127行,
                         因此当命令较多时建议写到脚本中执行
ENTRYPOINT ping www.aliyun.com #开机启动命令,此处最后一个命令需要是可在前台持续执行的命令,
                               否则容器后台运行时会因为命令执行完而退出。
Copy after login

Build the image.

docker build -t webcentos:v1 .   # . 是Dockerfile文件的路径,不能忽略
docker images                    #查看是否创建成功
docker run –d webcentos:v1       #后台运行容器
docker ps                        #查看当前运行中的容器
docker ps –a                     #查看所有容器,包括未运行中的
docker logs CONTAINER ID/IMAGE   #如未查看到刚才运行的容器,则用容器id或者名字查看启动日志排错
docker commit fb2844b6c070 dtstackweb:v1 #commit 后接容器id 和构建新镜像的名称和版本号。
docker images                    #列出本地(已下载的和本地创建的)镜像
docker push                      #将镜像推送至远程仓库,默认为 Docker Hub
Copy after login

Push the image to the registry.

docker login --username=dtstack_plus registry.cn-shanghai.aliyuncs.com #执行后输入镜像仓库密码
docker tag [ImageId] registry.cn-shanghai.aliyuncs.com/dtstack123/test:[镜像版本号]
docker push registry.cn-shanghai.aliyuncs.com/dtstack123/test:[镜像版本号]
Copy after login

If you can see the image version information in the image warehouse, it means the push is successful.

Please fill in [ImageId] and [Image version number] based on your own image information.

The above is the detailed content of How to build Docker on ECS in Linux operating system. For more information, please follow other related articles on the PHP Chinese website!

Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn

Hot Article

Hot Article

Hot Article Tags

Notepad++7.3.1

Notepad++7.3.1

Easy-to-use and free code editor

SublimeText3 Chinese version

SublimeText3 Chinese version

Chinese version, very easy to use

Zend Studio 13.0.1

Zend Studio 13.0.1

Powerful PHP integrated development environment

Dreamweaver CS6

Dreamweaver CS6

Visual web development tools

SublimeText3 Mac version

SublimeText3 Mac version

God-level code editing software (SublimeText3)

deepseek web version entrance deepseek official website entrance deepseek web version entrance deepseek official website entrance Feb 19, 2025 pm 04:54 PM

deepseek web version entrance deepseek official website entrance

Android TV Box gets unofficial Ubuntu 24.04 upgrade Android TV Box gets unofficial Ubuntu 24.04 upgrade Sep 05, 2024 am 06:33 AM

Android TV Box gets unofficial Ubuntu 24.04 upgrade

How to install deepseek How to install deepseek Feb 19, 2025 pm 05:48 PM

How to install deepseek

BitPie Bitpie wallet app download address BitPie Bitpie wallet app download address Sep 10, 2024 pm 12:10 PM

BitPie Bitpie wallet app download address

BITGet official website installation (2025 beginner's guide) BITGet official website installation (2025 beginner's guide) Feb 21, 2025 pm 08:42 PM

BITGet official website installation (2025 beginner's guide)

Zabbix 3.4 Source code compilation installation Zabbix 3.4 Source code compilation installation Sep 04, 2024 am 07:32 AM

Zabbix 3.4 Source code compilation installation

Detailed explanation: Shell script variable judgment parameter command Detailed explanation: Shell script variable judgment parameter command Sep 02, 2024 pm 03:25 PM

Detailed explanation: Shell script variable judgment parameter command

Ouyi okx installation package is directly included Ouyi okx installation package is directly included Feb 21, 2025 pm 08:00 PM

Ouyi okx installation package is directly included

See all articles