Docker project construction & deployment
# analysis
I have written two articles before, which are relatively complete descriptions of the application of container service in our company’s current business, but there is no specific description of how to construct and deploy. Therefore, this article mainly talks about how to container and deploy projects. After classifying our company’s business, there are the following types:
- Python application
- Node. Js applications
- PHP application
- Nginx service
- Docker Service (Server)
There are only two further categories:
As for project code, there are probably two or three code silos:
- coding
- github
- Gitlab (Private Library)
# building
# config reference
Add a Dockerfile to the root directory of the php-nginx project
# + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + # Ubuntu 14.04 PHP - Nginx Docker container # + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + the FROM webdevops/PHP: ubuntu 14.04 MAINTAINER [email protected] LABEL Vendor =WebDevOps. IO LABEL io.webDevops. Layout =5 LABEL io.webDevops WEB_DOCUMENT_INDEX index.php ENV WEB_ALIAS_DOMAIN *.vm # THINKPHP ENV # TP_CONFIG maybe one of aliyun-inner-pro,aliyun-outer-pro,aliyun-outer-test,localhost-dev,localhost-test ENV TP_DEBUG false ENV TP_CONFIG aliyun_outer_pro # Install nginx RUN /usr/local/bin/apt-install \ nginx # Deploy scripts/configurations RUN mkdir -p /app WORKDIR /app COPY src/ /app/ COPY conf/ /opt/docker/ RUN echo $TP_DEBUG > ThinkPHP.txt RUN echo $TP_CONFIG >> ThinkPHP.txt RUN bash /opt/docker/bin/control.sh provision.role.bootstrap webdevops-nginx \ && bash /opt/docker/bin/control.sh provision.role.bootstrap webdevops-php-nginx \ && bash /opt/docker/bin/bootstrap.sh EXPOSE 80 443 CMD ["supervisord"]Copy the code
# Mirror third party build service (our company is using & and supported code storehouse)
- Aliyun container service is built automatically
- github
- bitbucket
- local
- aliyun code
- Daocloud builds automatically
- github
- bitbucket
- coding
- Gitlab (Paid & Enterprise)
# Private build scheme for mirror
- gitlab-runner
- jenkins
- local push
# Webhook implementation
Both third-party services and private builds do three things:
# mkdir dir & pull code
cd workspace && mkdir {project name} && git pull {project repo} .
# build
docker build -t {project imageName}:{project commitId} .
# push image
docker push
Copy the code
The deployment of
# container deployment
In the previous article, we used Rancher-server as the administrative center of Docker (dCOS, UCP, etc.). In fact, when we started the image, we were already selecting the image
“Nginx” is the image, which can come from docker-Hub or private Registry
# Hybrid solution
There are two better-known tools. Python users should have heard of Fabric, and those interested can see the reference links below; The other is Ansible, also in the reference link below. Here’s ansible’s powerful remote management capabilities:
- Run commands on remote servers in batches
- Powerful playbook
- Can you define task queues and decide how to execute them according to different situations
- Repeatable (what is executed is not executed again)
- more
- See the Ansible documentation for more information
There are at least two things we can do with Ansible:
- Build docker images (overseas or domestic depending on the situation)
- Manually deploy & update code or update the container or code within the container
With these two functions, you can do more things, examples are as follows:
---
- hosts: webservers
vars:
http_port: 80
max_clients: 200
remote_user: root
tasks:
- name: ensure apache is at the latest version
yum: name=httpd state=latest
- name: write the apache config file
template: src=/srv/httpd.j2 dest=/etc/httpd.conf
notify:
- restart apache
- name: ensure apache is running (and enable it at boot)
service: name=httpd state=started enabled=yes
handlers:
- name: restart apache
service: name=httpd state=restarted
Copy the code
CI
# Continuous integration of third-party services
- Daocloud supports continuous integration
- Ali Cloud can be configured in the container service console
Continuous integration of private build solutions
Update the container or service using the Rancher API after playBook execution. See the Rancher documentation.
# reference
- dockerizing-your-frontend-project
- dockerizing-a-node-js-web-app
- python-fabric
- ansible documents
- rancher api documents
- Web project deployment scheme based on Docker & Fabric