2.3 Dockerfile创建镜像-Dockerfile示例

2018-05-27

2.3 Dockerfile 创建镜像-Dockerfile 示例

  创建一个 ubunt_nginx 目录,并进入

  先下载 nginx 的配置文件 wget http://www.apelearn.com/study_v2/.nginx_conf

  VIM Dockerfile //内容如下

###################################################

# Dockerfile to build Nginx Installed Containers

# Based on Ubuntu

###################################################

# Set the base image to Ubuntu

FROM ubuntu

# File Author / Maintainer

MAINTAINER user1 user1@test.com



# Install necessary tools

RUN apt-get update

RUN apt-get install -y libpcre3 libpcre3-dev wget net-tools gcc zlib1g zlib1g.dev make openssl libssl-dev

# Install Nginx

ADD http://nginx.org/download/nginx-1.8.0.tar.gz .

RUN tar zxvf nginx-1.8.0.tar.gz

RUN mkdir -p /usr/local/nginx

RUN cd nginx-1.8.0 && ./configure --prefix=/usr/local/nginx && make && make install

RUN rm -fv /usr/local/nginx/conf/nginx.conf

COPY ./nginx_conf /usr/local/nginx/conf/nginx.conf

# Expose ports

EXPOSE 80

# Set the default command to execute

# When creating a new container

#CMD /usr/local/nginx/sbin/nginx -c /usr/local/nginx/conf/nginx.conf

  创建镜像:

root@ubuntu:~/ubuntu_nginx# docker build -t ubuntu_nginx .

  查看镜像:

root@ubuntu:~/ubuntu_nginx# docker images

REPOSITORY                  TAG                 IMAGE ID            CREATED             VIRTUAL SIZE

ubuntu_nginx                latest              ae100581083f        10 minutes ago      302.6 MB

  启动容器,可以加上-p 选项指定端口映射

root@ubuntu:~# docker run -itd -p 1818:80 ubuntu_nginx bash

fe586657749e7d3815a7c092b0a4f06bd029e673b2a4bb3a3cddb7e198d69299

root@ubuntu:~# docker ps

CONTAINER ID        IMAGE                             COMMAND             CREATED             STATUS              PORTS                   NAMES

fe586657749e        ubuntu_nginx:latest               "bash"              40 seconds ago      Up 40 seconds       0.0.0.0:1818->80/tcp    drunk_perlman

标题:2.3 Dockerfile创建镜像-Dockerfile示例
作者:散宜生
地址:https://17kblog.com/articles/2018/05/27/1527428594832.html