dockerfile 制作基于ubuntu 的nginx 镜像

dockerfile 制作基于ubuntu 的nginx 镜像

1. 下载镜像
docker pull ubuntu:1804
2. 准备ubuntu的源

cat sources.list

deb http://mirrors.aliyun.com/ubuntu/ bionic main restricted universe multiverse
deb-src http://mirrors.aliyun.com/ubuntu/ bionic main restricted universe multiverse

deb http://mirrors.aliyun.com/ubuntu/ bionic-security main restricted universe multiverse
deb-src http://mirrors.aliyun.com/ubuntu/ bionic-security main restricted universe multiverse

deb http://mirrors.aliyun.com/ubuntu/ bionic-updates main restricted universe multiverse
deb-src http://mirrors.aliyun.com/ubuntu/ bionic-updates main restricted universe multiverse

deb http://mirrors.aliyun.com/ubuntu/ bionic-proposed main restricted universe multiverse
deb-src http://mirrors.aliyun.com/ubuntu/ bionic-proposed main restricted universe multiverse

deb http://mirrors.aliyun.com/ubuntu/ bionic-backports main restricted universe multiverse
deb-src http://mirrors.aliyun.com/ubuntu/ bionic-backports main restricted universe multiverse

3.准备nginx 的配置文件,页面文件,安装包

nginx.conf

user  nginx;
daemon off;

location /linux37 {
         root /data/nginx/html;
          index index.html;
        }

页面文件

root@z2:/opt/dockerfile/system/ubuntu# mkdir linux37
root@z2:/opt/dockerfile/system/ubuntu# echo nginx_ubuntu_test >linux37/index.html
root@z2:/opt/dockerfile/system/ubuntu# tar zcvf linux37.tar.gz  linux37/
linux37/
linux37/index.html

安装包

root@z2:/opt/dockerfile/system/ubuntu# wget http://nginx.org/download/nginx-1.16.1.tar.gz
4. 编写dockerfile
FROM ubuntu:18.04

maintainer zt "25958889@qq.com"

COPY sources.list /etc/apt/sources.list
 
RUN apt update && apt  install -y iproute2  ntpdate  tcpdump telnet traceroute nfs-kernel-server nfs-common  lrzsz tree  openssl libssl-dev libpcre3 libpcre3-dev zlib1g-dev ntpdate tcpdump telnet traceroute  gcc openssh-server lrzsz tree  openssl libssl-dev libpcre3 libpcre3-dev zlib1g-dev ntpdate tcpdump telnet traceroute iotop unzip zip make && touch /tmp/linux.txt

ADD nginx-1.16.1.tar.gz /usr/local/src
RUN cd /usr/local/src/nginx-1.16.1 && ./configure --prefix=/apps/nginx && make && make install && ln -sv /apps/nginx/sbin/nginx /usr/bin && rm -rf /usr/local/src/nginx-1.16.1 && rm -rf  /usr/local/src/nginx-1.16.1.tar.gz

ADD nginx.conf /apps/nginx/conf/nginx.conf
ADD linux37.tar.gz /data/nginx/html

RUN groupadd  -g 2019 nginx && useradd  -g nginx -s /usr/sbin/nologin -u 2019  nginx && chown -R nginx.nginx /apps/nginx /data/nginx

EXPOSE 80 443

CMD ["nginx"]
5.构建镜像,启动容器 ,测试

构建镜像

root@z2:/opt/dockerfile/system/ubuntu# cat build-command.sh 
#!/bin/bash
docker build -t ubuntu-nginx:1.16.1 .

root@z2:/opt/dockerfile/system/ubuntu# bash build-command.sh 

启动容器

root@z2:~# docker run -d -p 8082:80 ubuntu-nginx:1.16.1 
d7c5ccb25dc66d172d60a28fc936b12738b02fde2ab16057bc5c929d329ce424

测试

root@z2:~# curl 192.168.1.102:8082/linux37/
nginx_ubuntu_test
展开阅读全文

没有更多推荐了,返回首页

©️2019 CSDN 皮肤主题: 大白 设计师: CSDN官方博客
应支付0元
点击重新获取
扫码支付

支付成功即可阅读