例如:FROM centos FROM centos:latest
例如:MAINTAINER wyu wyu.com
例如:RUN yum install httpd
RUN [“/bin/bash”,”-c”,”echo hello”]
5、EXPOSE
例如:EXPOSE 22 80 8443用来指定要映射出去的端口,比如容器内部启动了sshd和nginx,所以要将22和80端口暴露出去,需要配合-P,在启动容器时加参数-P自动分配,-p指定具体端口。
例如:ENV PATH /usr/local/musql/bin:$PATH
ENV MYSQL_version 5.6
格式为 ADD
例如 VOLUME [“/data”]
例如:USER wyu
例如:WORKDIR /path/to/workdir
二、Dockerfile创建镜像
wget http://www.apelearn.com/study_v2/.nginx_conf
[root@oracle2 docker]# cat Dockerfile
##set the base image to CentOS
FROM centos
# File Author / Maintainer
MAINTAINER wyu wyu.com
# Install necessary tools
RUN yum install -y pcre-devel wget net-tools gcc zlib zlib-devel make openssl-devel
# 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
ENTRYPOINT /usr/local/nginx/sbin/nginx && tail -f /etc/passwd
[root@oracle2 docker]# docker build -t test1_nginx .
注意语句最后有个 . 意思为从当前目录寻找Dockerfile文件
4、查看创建的镜像
[root@oracle2 docker]# docker run -itd -p 8099:80 test1_nginx bash
1\docker compose可以方便我们快捷高效的管理容器的启动,停止,重启等操作,类似于Linux下的shell脚本,基于yaml语法,在该文件里可以描述应用的架构,比如使用镜像,数据卷,网络模式,监听端口等。
curl -L
https://github.com/docker/compose/releases/download/1.17.0-rc1/docker-compose-`uname -s`-`uname -m` > /usr/local/bin/docker-compose
chomd 755 /usr/local/bin/docker-compose
(1)编辑docker-compose.yml文件
[root@oracle2 ~]# cat docker-compose.yml
version: "2"
services:
app1:
image: centos_nginx
ports:
- "8080:80"
networks:
- "net1"
volumes:
- /data/:/data
app2:
image:wyu_net
networks:
- "net2"
volumes:
- /data/:/data1
entrypoint: tail -f /etc/passwd
networks:
net1:
driver: bridge
net2:
driver: bridge
(2)启动两个容器