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

How to build Docker on ECS in Linux operating system

坏嘻嘻
坏嘻嘻Original
2018-09-19 11:32:212033browse

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

Install and run Docker.

# yum install docker-io –y
# systemctl start docker

Check the installation results.

# docker info

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守护进程

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

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

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

View existing mirrors.

# docker images

Forced deletion of the image.

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

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

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

Enter the container running in the background.

# docker exec -ti apache /bin/bash

Make the container into a mirror.

# docker commit containerID/containerName  newImageName:tag

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

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

# docker run -d -p 8080:80 apachephp:v1

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 #开机启动命令,此处最后一个命令需要是可在前台持续执行的命令,
                               否则容器后台运行时会因为命令执行完而退出。

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

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:[镜像版本号]

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:
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