docker container to create and use

First prepare docker-ce of the rpm package

  1. Installation docker and start docker

yum install -y yum-utils device-mapper-persistent-data lvm2

yum-config-manager --add-repo http://mirrors.aliyun.com/docker-ce/linux/centos/docker-ce.repo

yum makecache fast

yum -y install docker-ce

we /etc/docker/daemon.json

 

#### Add the following content

{

  "registry-mirrors": ["https://dhq9bx4f.mirror.aliyuncs.com"]

}

##### save and exit

systemctl start docker

 

2. Start centos rear container mounting httpd and generate a new image

docker pull centos

### will get mirrored ID

docker run -itd - -name centos  /bin/bash

### will get the container ID

docker exec -it ( input container ID) bash

### into the docker after container:

yum install  -y httpd

### After installation, Ctrl + D to exit the container.

#### The following generates a new image by changing the container

docker commit -m "install httpd" -a "keyuan_test" ( input container ID)   new image name

### below the mirror created by the newly created container , and specify 8080: 80

docker run -itd -p 8080: 80 new image name    / bin / bash

#### into the following command docker container

docker exec -it new image container is generated ID bash

#### After entering the container, start httpd , and by ctrl + d to exit the container, using a browser or curl command to access the 80 -port

httpd -k start

curl localhost:8080

具体执行参考下面图形,特别时 镜像id和容器id的使用。

 

docker hub上拉centos镜像,并通过docker images 命令查看镜像ID

 

通过镜像id来启动容器,并通过docker exec 命令进入容器并安装httpd

 

在容器内httpd服务安装完成并ctrl+d退出。

 

查看当前启动的容器

通过这个容器id提交并生成新的镜像

通过新的镜像ID,启动容器,并映射8080端口到容器的80端口。

进入已安装httpd的容器并启动httpd后通过ctrl+d退出

通过curl的命令访问localhost:8080

表示成功映射到容器内部的80端口。

 

Guess you like

Origin www.cnblogs.com/yidaoyun/p/11595250.html