docker-compose

207 阅读1分钟

docker-compose部署

安装docker-compose

先编写以及配置服务端

[root@localhost ~]# curl -L https://github.com/docker/compose/releases/download/1.21.1/docker-compose-`uname -s`-`uname -m` -o /usr/local/bin/docker-compose
#网页下载软件
[root@localhost ~]# chmod +x /usr/local/bin/docker-compose
#安装软件,并给出执行权限
[root@localhost ~]# docker-compose --version
#查看版本
如果查看版本时候,有出现版本号

image.png

准备依赖文件

[root@localhost ~]# mkdir -p /opt/compose_nginx/nginx /opt/compose_nginx/wwwroot
[root@localhost ~]# cd /opt/compose_nginx/nginx
将nginx的安装包下载到此目录

[root@localhost nginx]# vim run.sh
#!/bin/bash
/usr/local/nginx/sbin/nginx

[root@localhost nginx]# vim Dockerfile
FROM centos:7
MAINTAINER this is nginx image <zly>
RUN yum -y update
#更新也可以不写上
RUN yum -y install pcre-devel zlib-devel gcc gcc-c++ make
RUN useradd -M -s /sbin/nologin nginx
ADD nginx-1.12.0.tar.gz /usr/local/src/
WORKDIR /usr/local/src/nginx-1.12.0
RUN ./comfigure \
--prefix=/usr/local/nginx \
--user=nginx \
--group=nginx \
--with-http_stub_status_module && make && make install
ENV PATH /usr/local/nginx/sbin:$PATH
EXPOSE 80
EXPOSE 443
RUN echo "daemon off;" >> /usr/local/nginx/conf/nginx.conf
ADD run.sh /run.sh
RUN chmod 755 /run.sh
CMD ["/run.sh"]
因为上面标记了一个run.sh,就可以直接使用
如果不使用run.sh,就使用此命令
ENTRYPOINT [ "/usr/local/nginx/sbin/nginx", "-g", "daemon off;" ]

[root@localhost nginx]# echo "<h1>this is test web</h1>" > /opt/compose_nginx/wwwroot/index.html

image.png

image.png

image.png

image.png

image.png

image.png

编写配置文件docker-compose.yml

[root@localhost nginx]# vim /opt/compose_nginx/docker-compose.yml
version:'3'
services:
 nginx:
  container_name:web1
  hostname:nginx
  build:
   context: ./nginx
   dockerfile: Dockerfile
  ports:
   - 1216:80
   - 1217:443
  networks:
   lnmp:
    ipv4_address:172.18.0.10
  volumes:
  - ./wwwroot:/usr/local/nginx/html
networks:
 lnmp:
  driver: bridge
  ipam:
   config:
    - subnet: 172.16.0.0/16

[root@localhost nginx]# cd /opt/compose_nginx/
[root@localhost compose_nginx]# docker-compose -f docker-compose.yml up -d

image.png

image.png

image.png