文章目录
使用Dockerfile制作基于Centos7的Nginx应用镜像
创建Dockerfile
dockerfile
FROM centos:7
MAINTAINER "WWW"
RUN yum install -y http://nginx.org/packages/centos/7/x86_64/RPMS/nginx-1.24.0-1.el7.ngx.x86_64.rpm
COPY dest/index.html /usr/share/nginx/html/
EXPOSE 80/tcp
ENTRYPOINT ["nginx", "-g", "daemon off;"]
创建镜像
bash
#目录结构
[root@docker nginx]# tree /root/dockerfile/
/root/dockerfile/
└── nginx
├── dest
│ └── index.html
└── Dockerfile
[root@docker nginx]# docker build -t centos:v1.1 ./
[root@docker nginx]# docker images
REPOSITORY TAG IMAGE ID CREATED SIZE
centos v1.1 90714e48dcba 2 minutes ago 431MB
上传镜像-harbor
修改hosts文件
bash
[root@docker nginx]# cat /etc/hosts
127.0.0.1 localhost localhost.localdomain localhost4 localhost4.localdomain4
::1 localhost localhost.localdomain localhost6 localhost6.localdomain6
192.168.110.139 www.kvm.cn
修改daemon.json
json
{
"registry-mirrors": ["https://hnjwpdu9.mirror.aliyuncs.com"],
"insecure-registries": ["www.kvm.cn"]
}
重启DOCKER
bash
[root@docker nginx]# systemctl restart docker.service
登录并上传
bash
[root@docker nginx]# docker login www.kvm.cn
Username: admin
Password:
WARNING! Your password will be stored unencrypted in /root/.docker/config.json.
Configure a credential helper to remove this warning. See
https://docs.docker.com/engine/reference/commandline/login/#credentials-store
Login Succeeded
[root@docker nginx]# docker push www.kvm.cn/library/centos7:v1.1
The push refers to repository [www.kvm.cn/library/centos7]
125496b805c2: Pushed
5efa92506a53: Pushed
174f56854903: Pushed
v1.1: digest: sha256:8cef5e2c8b505441ed50380961288c4f82d727cb34f0590bd2f2ebad6e820c25 size: 948
测试镜像
bash
[root@docker nginx]# docker run -d --name centos7v1.1 www.kvm.cn/library/centos7:v1.1
8220d8c238c1d865fd896fc66b972d3394fd84fff3b887424021c5de45345cac
[root@docker nginx]# docker ps
CONTAINER ID IMAGE COMMAND CREATED STATUS PORTS NAMES
8220d8c238c1 www.kvm.cn/library/centos7:v1.1 "nginx -g 'daemon of..." 5 seconds ago Up 5 seconds 80/tcp centos7v1.1
[root@docker nginx]# docker exec -it centos7v1.1 /bin/bash
[root@8220d8c238c1 /]# cat /usr/share/nginx/html/index.html
Nginx Web Test
[root@docker nginx]# curl 172.17.0.2
Nginx Web Test