docker-compose部署

发布时间:2024年01月15日

1、下载

curl -L https://github.com/docker/compose/releases/download/1.21.1/docker-compose-`uname -s`-`uname -m` -o /usr/local/bin/docker-compose

2、安装

chmod +x /usr/local/bin/docker-compose

3、查看版本

docker-compose --version

4、准备依赖文件

mkdir -p /opt/compose_nginx/nginx /opt/compose_nginx/wwwroot
cd /opt/compose_nginx/nginx
cp /opt/nginx-1.22.0.tar.gz ./
vim run.sh

vim Dockerfile
FROM centos:7
MAINTAINER this is nginx image <shh>
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.22.0.tar.gz /usr/local/src/
WORKDIR /usr/local/src/nginx-1.22.0
RUN ./configure \
--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"]

echo "<h1>this is test web</h1>" > /opt/compose_nginx/wwwroot/index.html

?

5、编写配置文件docker-compose.yml

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.18.0.0/16

cd /opt/compose_nginx/
docker-compose -f docker-compose.yml up -d

?这里因为报错,所以重启了docker,又运行了一遍这个命令

docker ps -a

cd /opt/compose_nginx/
docker-compose ps	

6、浏览器访问:http://192.168.246.10:1216

?

文章来源:https://blog.csdn.net/m0_73792056/article/details/135599610
本文来自互联网用户投稿,该文观点仅代表作者本人,不代表本站立场。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。