下载地址:https://github.com/rickding/HelloDocker/
如果觉得这篇文章有帮助,请关注转发。
Docker容器快捷高效部署应用,资源编排定义和运行多个容器,通过docker-compose.yml配置文件声明各个服务,作为一个整体来创建和启动。
软件开发时常用的开发运行环境,安装配置有些繁琐,新工程师或者新机器经常要花费不少时间,为什么不试试Docker-compose一键部署?
一,下载脚本源码
https://github.com/rickding/HelloDocker/
子目录中脚本文件
├── build.sh
├── Dockerfile
├── docker-compose.yml
├── pull.sh
├── up.sh
├── logs.sh
├── down.sh
二,安装Docker环境
Ubuntu环境下可运行代码库中脚本docker.sh自动安装。
https://docs.docker.com/install/linux/docker-ce/ubuntu/
https://docs.docker.com/docker-for-windows/install/
三,启动开发运行环境
1. Dockerfile配置是核心
以常用的Ngnix为例,自定义配置,然后打包进镜像。
FROM nginx:latest
# web files
COPY ./web/ /usr/share/nginx/html
# config
COPY ./conf/ /etc/nginx/
WORKDIR /etc/nginx
EXPOSE 80
2. 配置docker-compose.yml
version: "3"
services:
nginx:
image: nginx_local:latest
build: .
restart: always
ports:
- "80:80"
3. pull.sh拉取镜像
可直接运行docker pull nginx:latest拉取镜像,docker images查看:
4. build.sh构建镜像
可直接运行docker-compose build
5. up.sh启动容器
脚本中封装了docker-compose up -d命令,启动后运行docker ps查看容器实例:
6. logs.sh查看日志
定制命令突出显示重要信息:
docker-compose logs -ft | grep --color -i -e error -e warn -e version -e exception
7. down.sh停止服务
docker-compose down --remove-orphans停止并删除容器:
8. 查看服务
可以在docker-compose.yml中配置多个运行环境同时启动,docker一键部署,就是这么简单任性。
閱讀更多 Web應用架構師 的文章