1.编写Dockerfile文件,添加如下内容并保存
命令:
vim Dockerfile
[root@centos79 ~]# cat Dockerfile
FROM centos:centos7
MAINTAINER ztj
ENV PATH /usr/local/nginx/sbin:$PATH
ADD nginx-1.8.0.tar.gz /usr/local/
ADD epel-release-latest-7.noarch.rpm /usr/local/
RUN rpm -ivh /usr/local/epel-release-latest-7.noarch.rpm
RUN yum install -y vim net-tools wget lftp gcc gcc-c++ make openssl-devel pcre-devel pcre && yum clean all
RUN useradd -s /sbin/nologin -M www
WORKDIR /usr/local/nginx-1.8.0
RUN ./configure --prefix=/usr/local/nginx --user=www --group=www --with-http_ssl_module --with-pcre && make && make install
RUN echo "daemon off;" >>/etc/nginx.conf
EXPOSE 80
ENTRYPOINT ["nginx"]
CMD ["-g","daemon off;"]
[root@centos79 ~]#
2.构建镜像及查看
命令:
docker build -t centos-nginx:1.0 -f /root/Dockerfile .
[root@centos79 ~]# docker build -t centos-nginx:1.0 -f /root/Dockerfile .
[+] Building 56.8s (8/13)
=> [internal] load build definition from Dockerfile
=> => transferring dockerfile: 656B
=> [internal] load .dockerignore
=> => transferring context: 2B
[+] Building 57.0s (8/13) docker:default
=> [1/9] FROM docker.io/library/centos:centos7 0.0s
=> [internal] load build context 0.0s
=> => transferring context: 93B 0.0s
=> [2/9] ADD nginx-1.8.0.tar.gz /usr/local/ 0.2s
[+] Building 232.7s (14/14) FINISHED docker:default
=> [internal] load build definition from Dockerfile 0.0s
=> => transferring dockerfile: 656B 0.0sea
=> [internal] load .dockerignore 0.0s
=> => transferring context: 2B 0.0s
=> [internal] load metadata for docker.io/library/centos:centos7 0.0s
=> [1/9] FROM docker.io/library/centos:centos7 0.0s
=> [internal] load build context 0.0s
=> => transferring context: 93B 0.0s
=> [2/9] ADD nginx-1.8.0.tar.gz /usr/local/ 0.2s
=> [3/9] ADD epel-release-latest-7.noarch.rpm /usr/local/ 0.0s
=> [4/9] RUN rpm -ivh /usr/local/epel-release-latest-7.noarch.rpm 1.1s
=> [5/9] RUN yum install -y vim net-tools wget lftp gcc gcc-c++ make openssl-devel pcre-devel pcre & 211.4s
=> [6/9] RUN useradd -s /sbin/nologin -M www 0.3s
=> [7/9] WORKDIR /usr/local/nginx-1.8.0 0.0s
=> [8/9] RUN ./configure --prefix=/usr/local/nginx --user=www --group=www --with-http_ssl_module --wi 18.4s
=> [9/9] RUN echo "daemon off;" >>/etc/nginx.conf 0.3s
=> exporting to image 0.9s
=> => exporting layers 0.9s
=> => writing image sha256:69ec253478f5af7b26d691906a337d48758819bc8b10293a96a3e688d69ae04e 0.0s
=> => naming to docker.io/library/centos-nginx:1.0 0.0s
[root@centos79 ~]#
3.查看镜像
命令:
docker images | grep centos-nginx
[root@centos79 ~]# docker images | grep centos-nginx
centos-nginx 1.0 69ec253478f5 About a minute ago 448MB
[root@centos79 ~]#
4.运行镜像
命令:
docker run -itd -p 80:80 --name centos-nginx centos-nginx:1.0
[root@centos79 ~]# docker run -itd -p 80:80 --name centos-nginx centos-nginx:1.0
f5e0a3d00d0e4f43809b9734e8b501521482d43141f772899f412dc6b43a3bda
[root@centos79 ~]# docker ps -a | grep centos-nginx
f5e0a3d00d0e centos-nginx:1.0 "nginx -g 'daemon of…" 48 seconds ago Up 47 seconds 0.0.0.0:80->80/tcp, :::80->80/tcp centos-nginx
[root@centos79 ~]# netstat -antulp | grep 80
tcp 0 0 0.0.0.0:80 0.0.0.0:* LISTEN 13186/docker-proxy
......
tcp6 0 0 :::80 :::* LISTEN 13192/docker-proxy
[root@centos79 ~]#
5.验证
标签:centos,application,--,0.0,nginx,Docker,local,docker From: https://blog.51cto.com/ztj1216/9587284