{"id":334677,"date":"2022-06-18T15:00:07","date_gmt":"2022-06-18T15:00:07","guid":{"rendered":"http:\/\/savepearlharbor.com\/?p=334677"},"modified":"-0001-11-30T00:00:00","modified_gmt":"-0001-11-29T21:00:00","slug":"","status":"publish","type":"post","link":"https:\/\/savepearlharbor.com\/?p=334677","title":{"rendered":"<span>\u041a\u0430\u043a \u0441\u043e\u0437\u0434\u0430\u0432\u0430\u0442\u044c \u043e\u0431\u0440\u0430\u0437\u044b Docker \u0441 \u043f\u043e\u043c\u043e\u0449\u044c\u044e Ansible \u0432 Ubuntu 20.04<\/span>"},"content":{"rendered":"<div><\/div>\n<div id=\"post-content-body\">\n<div>\n<div class=\"article-formatted-body article-formatted-body article-formatted-body_version-2\">\n<div xmlns=\"http:\/\/www.w3.org\/1999\/xhtml\">\n<p>\u0421\u0435\u0433\u043e\u0434\u043d\u044f \u044f \u0431\u044b \u0445\u043e\u0442\u0435\u043b \u0440\u0430\u0441\u0441\u043a\u0430\u0437\u0430\u0442\u044c, \u043a\u0430\u043a \u0441\u043e\u0437\u0434\u0430\u0432\u0430\u0442\u044c \u043e\u0431\u0440\u0430\u0437\u044b Docker \u0441 \u043f\u043e\u043c\u043e\u0449\u044c\u044e Ansible.<\/p>\n<p>\u041d\u043e \u0434\u043b\u044f \u043d\u0430\u0447\u0430\u043b\u0430 \u0440\u0430\u0441\u0441\u043a\u0430\u0436\u0443 \u043a\u0440\u0430\u0442\u043a\u043e \u0447\u0442\u043e \u0442\u0430\u043a\u043e\u0435 Docker. Docker \u2013 \u044d\u0442\u043e \u0441\u043e\u0444\u0442 \u0434\u043b\u044f \u0432\u0438\u0440\u0442\u0443\u0430\u043b\u0438\u0437\u0430\u0446\u0438\u0438 \u0438 \u043e\u043d \u043f\u043e\u0437\u0432\u043e\u043b\u044f\u0435\u0442 \u0432\u0430\u043c \u0443\u043f\u0430\u043a\u043e\u0432\u044b\u0432\u0430\u0442\u044c \u0432\u0430\u0448\u0438 \u043f\u0440\u0438\u043b\u043e\u0436\u0435\u043d\u0438\u044f \u0432 \u043a\u043e\u043d\u0442\u0435\u0439\u043d\u0435\u0440\u044b.<\/p>\n<p>\u0427\u0442\u043e \u0442\u0430\u043a\u043e\u0435 Ansible \u2013 \u044d\u0442\u043e \u0441\u043e\u0444\u0442 \u0434\u043b\u044f \u0443\u043f\u0440\u0430\u0432\u043b\u0435\u043d\u0438\u044f \u043a\u043e\u043d\u0444\u0438\u0433\u0443\u0440\u0430\u0446\u0438\u044f\u043c\u0438, \u0432 \u0447\u0430\u0441\u0442\u043d\u043e\u0441\u0442\u0438 \u0443\u043f\u0440\u0430\u0432\u043b\u0435\u043d\u0438\u0435 \u043a\u043e\u043d\u0444\u0438\u0433\u0443\u0440\u0430\u0446\u0438\u044f\u043c\u0438 \u043e\u043f\u0435\u0440\u0430\u0446\u0438\u043e\u043d\u043d\u044b\u0445 \u0441\u0438\u0441\u0442\u0435\u043c.<\/p>\n<p>\u0414\u043b\u044f \u043d\u0430\u0447\u0430\u043b\u0430 \u043d\u0430\u043c \u043d\u0443\u0436\u043d\u043e \u0443\u0441\u0442\u0430\u043d\u043e\u0432\u0438\u0442\u044c Docker \u0438 Ansible, \u0437\u0430\u0442\u0435\u043c \u0441\u043e\u0437\u0434\u0430\u0434\u0438\u043c Docker \u0444\u0430\u0439\u043b \u0438 \u0441\u043e\u0431\u0435\u0440\u0435\u043c \u043a\u043e\u043d\u0442\u0435\u0439\u043d\u0435\u0440 \u0434\u043b\u044f Web-\u0441\u0435\u0440\u0432\u0435\u0440\u0430. \u041f\u043e\u0441\u043b\u0435 \u044d\u0442\u043e\u0433\u043e \u043c\u044b \u0441\u043e\u0437\u0434\u0430\u0434\u0438\u043c \u043f\u0440\u043e\u0441\u0442\u043e\u0439 \u043f\u043b\u0435\u0439\u0431\u0443\u043a Ansible \u0434\u043b\u044f \u0441\u043e\u0437\u0434\u0430\u043d\u0438\u044f \u043e\u0431\u0440\u0430\u0437\u0430 Docker \u0434\u043b\u044f \u0434\u0440\u0443\u0433\u043e\u0433\u043e Web-\u0441\u0435\u0440\u0432\u0435\u0440\u0430.<\/p>\n<h3>\u0423\u0441\u0442\u0430\u043d\u0430\u0432\u043b\u0438\u0432\u0430\u0435\u043c Docker<\/h3>\n<blockquote>\n<p><code>sudo apt-get install apt-transport-https ca-certificates curl gnupg-agent software-properties-common<\/code><\/p>\n<p><code>curl -fsSL https:\/\/download.docker.com\/linux\/ubuntu\/gpg | sudo apt-key add -<\/code><\/p>\n<p><code>sudo add-apt-repository \u201cdeb [arch=amd64] https:\/\/download.docker.com\/linux\/ubuntu $(lsb_release -cs) stable\u201d<\/code><\/p>\n<p><code>sudo apt update<\/code><\/p>\n<p><code>sudo apt install docker-ce docker-ce-cli containerd.io<\/code><\/p>\n<p><code>sudo groupadd docker<\/code><\/p>\n<p><code>sudo usermod -aG docker $USER<\/code><\/p>\n<\/blockquote>\n<p>\u0422\u0435\u043f\u0435\u0440\u044c \u0432\u0430\u043c \u043d\u0430\u0434\u043e \u043f\u0435\u0440\u0435\u043b\u043e\u0433\u0438\u043d\u0438\u0442\u044c\u0441\u044f \u0432 \u043e\u043f\u0435\u0440\u0430\u0446\u0438\u043e\u043d\u043d\u043e\u0439 \u0441\u0438\u0441\u0442\u0435\u043c\u0435 \u0438 \u043f\u0440\u043e\u0432\u0435\u0440\u044f\u0435\u043c \u0432\u0435\u0440\u0441\u0438\u044e \u0443\u0441\u0442\u0430\u043d\u043e\u0432\u043b\u0435\u043d\u043d\u043e\u0433\u043e Docker:<\/p>\n<blockquote>\n<p><code>docker --version<\/code><\/p>\n<\/blockquote>\n<h3>\u0423\u0441\u0442\u0430\u043d\u0430\u0432\u043b\u0438\u0432\u0430\u0435\u043c Ansible<\/h3>\n<blockquote>\n<p><code>sudo apt install ansible<\/code><\/p>\n<\/blockquote>\n<p>\u0412\u0441\u0451.<\/p>\n<h3>\u0423\u0441\u0442\u0430\u043d\u043e\u0432\u043a\u0430 \u0434\u043e\u043f\u043e\u043b\u043d\u0438\u0442\u0435\u043b\u044c\u043d\u043e\u0433\u043e \u0441\u043e\u0444\u0442\u0430<\/h3>\n<p>\u0412\u044b\u0448\u0435 \u043c\u044b \u0443\u0441\u0442\u0430\u043d\u043e\u0432\u0438\u043b\u0438 \u043e\u0441\u043d\u043e\u0432\u043d\u043e\u0439 \u0441\u043e\u0444\u0442, \u043d\u043e \u0434\u043b\u044f \u043f\u043e\u043b\u043d\u043e\u0446\u0435\u043d\u043d\u043e\u0439 \u0440\u0430\u0431\u043e\u0442\u044b \u043d\u0430\u043c \u043d\u0430\u0434\u043e \u0443\u0441\u0442\u0430\u043d\u043e\u0432\u0438\u0442\u044c \u0434\u043e\u043f\u043e\u043b\u043d\u0438\u0442\u0435\u043b\u044c\u043d\u044b\u0435 \u043f\u0430\u043a\u0435\u0442\u044b.<\/p>\n<blockquote>\n<p><code>sudo apt install python3-pip<\/code><\/p>\n<p><code>pip3 install docker<\/code><\/p>\n<\/blockquote>\n<h3>\u0422\u0435\u043f\u0435\u0440\u044c \u0434\u0430\u0432\u0430\u0439\u0442\u0435 \u043f\u0438\u0441\u0430\u0442\u044c \u043a\u043e\u0434<\/h3>\n<p>\u0412\u0435\u0441\u044c \u043a\u043e\u0434, \u043a\u043e\u0442\u043e\u0440\u044b\u0439 \u0431\u0443\u0434\u0435\u0442 \u043f\u0440\u0435\u0434\u043e\u0441\u0442\u0430\u0432\u043b\u0435\u043d \u0434\u0430\u043b\u044c\u0448\u0435, \u0432\u044b \u043c\u043e\u0436\u0435\u0442\u0435 \u0441\u043a\u0430\u0447\u0430\u0442\u044c <a href=\"https:\/\/github.com\/ZeroBot-Dot\/Build-Docker-Images-with-Ansible\" rel=\"noopener noreferrer nofollow\">\u0432 \u043c\u043e\u0435\u043c \u0440\u0435\u043f\u043e\u0437\u0438\u0442\u043e\u0440\u0438\u0438 \u043d\u0430 GitHub<\/a>.<\/p>\n<p>\u0421\u043e\u0437\u0434\u0430\u0435\u043c \u043f\u0430\u043f\u043a\u0443 docker-build \u0438 \u0432 \u043d\u0435\u0439 \u0441\u043e\u0437\u0434\u0430\u0435\u043c \u0444\u0430\u0439\u043b Dockerfile, \u043e\u043d \u0431\u0443\u0434\u0435\u0442 \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u0442\u044c\u0441\u044f \u0434\u043b\u044f \u0441\u043e\u0437\u0434\u0430\u043d\u0438\u044f Docker image.<\/p>\n<p><strong>\u0421\u043e\u0434\u0435\u0440\u0436\u0438\u043c\u043e\u0435 \u0444\u0430\u0439\u043b\u0430:<\/strong><\/p>\n<blockquote>\n<p><code>FROM nginx:latest<\/p>\n<p># Default Nginx static file location<br \/># Ideally, we would edit the nginx.conf for new configuration<br \/>WORKDIR \/usr\/share\/nginx\/html<\/p>\n<p># Add all local static files to image working directory<br \/>ADD .\/ .\/<\/p>\n<p># If there was a lot of ADD COPY and RUN Steps, Bash script file is common practice<br \/># To bootstrap the image without additional layers<br \/># RUN \/bootstrap.sh<\/p>\n<p># Self explanatory<br \/>EXPOSE 8080<\/code><\/p>\n<\/blockquote>\n<p>\u0422\u0435\u043f\u0435\u0440\u044c \u0441\u043e\u0437\u0434\u0430\u0434\u0438\u043c \u0440\u044f\u0434\u043e\u043c \u0441 \u043f\u0430\u043f\u043a\u043e\u0439 docker-build \u043f\u0430\u043f\u043a\u0443 ansible-build. \u0412 \u043d\u0435\u0439 \u0441\u043e\u0437\u0434\u0430\u0435\u043c \u0444\u0430\u0439\u043b docker-image-playbook.yaml<\/p>\n<p><strong>\u0421\u043e\u0434\u0435\u0440\u0436\u0438\u043c\u043e\u0435 \u0444\u0430\u0439\u043b\u0430:<\/strong><\/p>\n<blockquote>\n<p><code>---<br \/>- name: Pull latest Nginx Image<br \/>\u00a0 hosts: localhost<br \/>\u00a0 tasks:<br \/>\u00a0\u00a0\u00a0 - name: Pull Nginx Image<br \/>\u00a0\u00a0\u00a0\u00a0\u00a0 docker_container:<br \/>\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0 name: \u00abnginx-ansible-base\u00bb<br \/>\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0 image: \u00abnginx:latest\u00bb<br \/>\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0 state: started<br \/>\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0 command: tail -f \/dev\/null<br \/>\u00a0\u00a0\u00a0 - name: Add Nginx Image to Ansible Hosts<br \/>\u00a0\u00a0\u00a0\u00a0\u00a0 add_host:<br \/>\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0 name: \u00abnginx-ansible-base\u00bb<br \/>\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0 ansible_connection: docker<br \/>\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0 ansible_ssh_user: root<br \/>- name: Configure Nginx Base Image for deploying Webserver<br \/>\u00a0 hosts: \u00abnginx-ansible-base\u00bb<br \/>\u00a0 gather_facts: false<br \/>\u00a0 tasks:<br \/>\u00a0\u00a0\u00a0 - name: Install Python3<br \/>\u00a0\u00a0\u00a0\u00a0\u00a0 raw: apt update &amp;&amp; apt upgrade -y &amp;&amp; apt install python3 -y<br \/>\u00a0\u00a0\u00a0 - name: Install Rsync<br \/>\u00a0\u00a0\u00a0\u00a0\u00a0 apt:<br \/>\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0 name: rsync<br \/>\u00a0\u00a0\u00a0 - name: Copy local configuration Files to Nginx Conf<br \/>\u00a0\u00a0\u00a0\u00a0\u00a0 synchronize:<br \/>\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0 src: .\/website\/<br \/>\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0 dest: \/usr\/share\/nginx\/html\/<br \/>\u00a0 \u00a0\u00a0- name: Ensure NGINX Is enabled<br \/>\u00a0\u00a0\u00a0\u00a0\u00a0 service:<br \/>\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0 name: nginx<br \/>\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0 enabled: yes<br \/>\u00a0\u00a0\u00a0 - name: Clean up Python 3 and Prerequisites<br \/>\u00a0\u00a0\u00a0\u00a0\u00a0 raw: apt purge python3 rsync -y<br \/>- name: Snapshot base image to create newly configured Image<br \/>\u00a0 hosts: localhost<br \/>\u00a0 tasks:<br \/>\u00a0\u00a0\u00a0 - name: Commit Docker image<br \/>\u00a0\u00a0\u00a0\u00a0\u00a0 command: docker commit \u00abnginx-ansible-base\u00bb \u00abnginx-ansible-build-demo\u00bb<br \/>- name: Clean Up Docker Containers<br \/>\u00a0 hosts: localhost<br \/>\u00a0 tasks:<br \/>\u00a0\u00a0\u00a0 - name: Remove Running Base Image<br \/>\u00a0\u00a0\u00a0\u00a0\u00a0 docker_container:<br \/>\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0 name: nginx-ansible-base<br \/>\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0 state: absent<br \/>\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0 force_kill: yes<\/code><\/p>\n<\/blockquote>\n<p>\u0412 \u044d\u0442\u043e\u043c \u0444\u0430\u0439\u043b\u0435 \u043e\u043f\u0438\u0441\u044b\u0432\u0430\u044e\u0442\u0441\u044f \u043a\u043e\u043c\u0430\u043d\u0434\u044b, \u043a\u043e\u0442\u043e\u0440\u044b\u0435 \u0431\u0443\u0434\u0435\u0442 \u0432\u044b\u043f\u043e\u043b\u043d\u044f\u0442\u044c Ansible.<\/p>\n<p>\u041f\u043e \u0444\u0430\u043a\u0442\u0443 \u0432 \u044d\u0442\u043e\u043c \u0444\u0430\u0439\u043b\u0435 \u043e\u043f\u0438\u0441\u0430\u043d\u0430 \u0441\u0431\u043e\u0440\u043a\u0430 \u043a\u043e\u043d\u0442\u0435\u0439\u043d\u0435\u0440\u0430 Docker \u043d\u0430 \u043e\u0441\u043d\u043e\u0432\u0430\u043d\u0438\u0438 \u043d\u0443\u0436\u043d\u043e\u0433\u043e \u043d\u0430\u043c \u043e\u0431\u0440\u0430\u0437\u0430, \u0443\u0441\u0442\u0430\u043d\u043e\u0432\u043a\u0430 \u0437\u0430\u0432\u0438\u0441\u0438\u043c\u043e\u0441\u0442\u0435\u0439 \u0438 \u043a\u043e\u043f\u0438\u0440\u043e\u0432\u0430\u043d\u0438\u0435 \u043d\u0435\u043e\u0431\u0445\u043e\u0434\u0438\u043c\u044b\u0445 \u0444\u0430\u0439\u043b\u043e\u0432. \u041d\u0435 \u0432\u0438\u0436\u0443 \u0441\u043c\u044b\u0441\u043b\u0430 \u043a\u043e\u043f\u0438\u0440\u043e\u0432\u0430\u0442\u044c \u0441\u044e\u0434\u0430 \u043e\u0444\u0438\u0446\u0438\u0430\u043b\u044c\u043d\u0443\u044e \u0434\u043e\u043a\u0443\u043c\u0435\u043d\u0442\u0430\u0446\u0438\u044e, \u043e\u043d\u0430 \u043c\u043e\u0436\u0435\u0442 \u043f\u043e\u0442\u0435\u0440\u044f\u0442\u044c \u0430\u043a\u0442\u0443\u0430\u043b\u044c\u043d\u043e\u0441\u0442\u044c, \u043f\u043e\u044d\u0442\u043e\u043c\u0443 \u0440\u0435\u043a\u043e\u043c\u0435\u043d\u0434\u0443\u044e \u0432\u0430\u043c \u0438\u0437\u0443\u0447\u0438\u0442\u044c \u0435\u0435 \u043d\u0430 \u043e\u0444\u0438\u0446\u0438\u0430\u043b\u044c\u043d\u043e\u043c \u0441\u0430\u0439\u0442\u0435 Ansible.<\/p>\n<p>\u0427\u0442\u043e\u0431\u044b \u0441\u043e\u0431\u0440\u0430\u0442\u044c \u043e\u0431\u0440\u0430\u0437 \u043d\u0430 \u043e\u0441\u043d\u043e\u0432\u0430\u043d\u0438\u0438 \u0442\u043e\u043b\u044c\u043a\u043e \u0447\u0442\u043e \u0441\u043e\u0437\u0434\u0430\u043d\u043d\u043e\u0433\u043e \u0444\u0430\u0439\u043b\u0430 docker-image-playbook.yaml \u0432\u0432\u043e\u0434\u0438\u043c \u0432 \u043a\u043e\u043d\u0441\u043e\u043b\u0438 \u043a\u043e\u043c\u0430\u043d\u0434\u0443 ansible-playbook docker-image-playbook.yaml<\/p>\n<p>\u0412 \u0440\u0435\u043f\u043e\u0437\u0438\u0442\u043e\u0440\u0438\u0438 \u0432\u044b \u043d\u0430\u0439\u0434\u0435\u0442\u0435 \u0435\u0449\u0435 \u0444\u0430\u0439\u043b\u044b \u043e\u0442 \u0434\u0432\u0443\u0445 html \u0448\u0430\u0431\u043b\u043e\u043d\u043e\u0432 \u0441\u0430\u0439\u0442\u043e\u0432. \u041e\u043d\u0438 \u0434\u043e\u0431\u0430\u0432\u043b\u0435\u043d\u044b \u0447\u0442\u043e\u0431\u044b \u043f\u0440\u0438 \u0437\u0430\u043f\u0443\u0441\u043a\u0435 \u043a\u043e\u043d\u0442\u0435\u0439\u043d\u0435\u0440\u0430 Docker \u0447\u0435\u0440\u0435\u0437 Dockerfile \u0438 \u0447\u0435\u0440\u0435\u0437 \u0444\u0430\u0439\u043b docker-image-playbook.yaml \u0432\u044b \u043c\u043e\u0433\u043b\u0438 \u0443\u0432\u0438\u0434\u0435\u0442\u044c \u0440\u0430\u0437\u043d\u0438\u0446\u0443 (\u0448\u0430\u0431\u043b\u043e\u043d\u044b \u043e\u0442\u043b\u0438\u0447\u0430\u044e\u0442\u0441\u044f \u0434\u0440\u0443\u0433 \u043e\u0442 \u0434\u0440\u0443\u0433\u0430).<\/p>\n<\/div>\n<\/div>\n<\/div>\n<div class=\"v-portal\" style=\"display:none;\"><\/div>\n<\/div>\n<p> <!----> <!----><br \/> \u0441\u0441\u044b\u043b\u043a\u0430 \u043d\u0430 \u043e\u0440\u0438\u0433\u0438\u043d\u0430\u043b \u0441\u0442\u0430\u0442\u044c\u0438 <a href=\"https:\/\/habr.com\/ru\/post\/672162\/\"> https:\/\/habr.com\/ru\/post\/672162\/<\/a><\/p>\n","protected":false},"excerpt":{"rendered":"<div><\/div>\n<div id=\"post-content-body\">\n<div>\n<div class=\"article-formatted-body article-formatted-body article-formatted-body_version-2\">\n<div xmlns=\"http:\/\/www.w3.org\/1999\/xhtml\">\n<p>\u0421\u0435\u0433\u043e\u0434\u043d\u044f \u044f \u0431\u044b \u0445\u043e\u0442\u0435\u043b \u0440\u0430\u0441\u0441\u043a\u0430\u0437\u0430\u0442\u044c, \u043a\u0430\u043a \u0441\u043e\u0437\u0434\u0430\u0432\u0430\u0442\u044c \u043e\u0431\u0440\u0430\u0437\u044b Docker \u0441 \u043f\u043e\u043c\u043e\u0449\u044c\u044e Ansible.<\/p>\n<p>\u041d\u043e \u0434\u043b\u044f \u043d\u0430\u0447\u0430\u043b\u0430 \u0440\u0430\u0441\u0441\u043a\u0430\u0436\u0443 \u043a\u0440\u0430\u0442\u043a\u043e \u0447\u0442\u043e \u0442\u0430\u043a\u043e\u0435 Docker. Docker \u2013 \u044d\u0442\u043e \u0441\u043e\u0444\u0442 \u0434\u043b\u044f \u0432\u0438\u0440\u0442\u0443\u0430\u043b\u0438\u0437\u0430\u0446\u0438\u0438 \u0438 \u043e\u043d \u043f\u043e\u0437\u0432\u043e\u043b\u044f\u0435\u0442 \u0432\u0430\u043c \u0443\u043f\u0430\u043a\u043e\u0432\u044b\u0432\u0430\u0442\u044c \u0432\u0430\u0448\u0438 \u043f\u0440\u0438\u043b\u043e\u0436\u0435\u043d\u0438\u044f \u0432 \u043a\u043e\u043d\u0442\u0435\u0439\u043d\u0435\u0440\u044b.<\/p>\n<p>\u0427\u0442\u043e \u0442\u0430\u043a\u043e\u0435 Ansible \u2013 \u044d\u0442\u043e \u0441\u043e\u0444\u0442 \u0434\u043b\u044f \u0443\u043f\u0440\u0430\u0432\u043b\u0435\u043d\u0438\u044f \u043a\u043e\u043d\u0444\u0438\u0433\u0443\u0440\u0430\u0446\u0438\u044f\u043c\u0438, \u0432 \u0447\u0430\u0441\u0442\u043d\u043e\u0441\u0442\u0438 \u0443\u043f\u0440\u0430\u0432\u043b\u0435\u043d\u0438\u0435 \u043a\u043e\u043d\u0444\u0438\u0433\u0443\u0440\u0430\u0446\u0438\u044f\u043c\u0438 \u043e\u043f\u0435\u0440\u0430\u0446\u0438\u043e\u043d\u043d\u044b\u0445 \u0441\u0438\u0441\u0442\u0435\u043c.<\/p>\n<p>\u0414\u043b\u044f \u043d\u0430\u0447\u0430\u043b\u0430 \u043d\u0430\u043c \u043d\u0443\u0436\u043d\u043e \u0443\u0441\u0442\u0430\u043d\u043e\u0432\u0438\u0442\u044c Docker \u0438 Ansible, \u0437\u0430\u0442\u0435\u043c \u0441\u043e\u0437\u0434\u0430\u0434\u0438\u043c Docker \u0444\u0430\u0439\u043b \u0438 \u0441\u043e\u0431\u0435\u0440\u0435\u043c \u043a\u043e\u043d\u0442\u0435\u0439\u043d\u0435\u0440 \u0434\u043b\u044f Web-\u0441\u0435\u0440\u0432\u0435\u0440\u0430. \u041f\u043e\u0441\u043b\u0435 \u044d\u0442\u043e\u0433\u043e \u043c\u044b \u0441\u043e\u0437\u0434\u0430\u0434\u0438\u043c \u043f\u0440\u043e\u0441\u0442\u043e\u0439 \u043f\u043b\u0435\u0439\u0431\u0443\u043a Ansible \u0434\u043b\u044f \u0441\u043e\u0437\u0434\u0430\u043d\u0438\u044f \u043e\u0431\u0440\u0430\u0437\u0430 Docker \u0434\u043b\u044f \u0434\u0440\u0443\u0433\u043e\u0433\u043e Web-\u0441\u0435\u0440\u0432\u0435\u0440\u0430.<\/p>\n<h3>\u0423\u0441\u0442\u0430\u043d\u0430\u0432\u043b\u0438\u0432\u0430\u0435\u043c Docker<\/h3>\n<blockquote>\n<p><code>sudo apt-get install apt-transport-https ca-certificates curl gnupg-agent software-properties-common<\/code><\/p>\n<p><code>curl -fsSL https:\/\/download.docker.com\/linux\/ubuntu\/gpg | sudo apt-key add -<\/code><\/p>\n<p><code>sudo add-apt-repository \u201cdeb [arch=amd64] https:\/\/download.docker.com\/linux\/ubuntu $(lsb_release -cs) stable\u201d<\/code><\/p>\n<p><code>sudo apt update<\/code><\/p>\n<p><code>sudo apt install docker-ce docker-ce-cli containerd.io<\/code><\/p>\n<p><code>sudo groupadd docker<\/code><\/p>\n<p><code>sudo usermod -aG docker $USER<\/code><\/p>\n<\/blockquote>\n<p>\u0422\u0435\u043f\u0435\u0440\u044c \u0432\u0430\u043c \u043d\u0430\u0434\u043e \u043f\u0435\u0440\u0435\u043b\u043e\u0433\u0438\u043d\u0438\u0442\u044c\u0441\u044f \u0432 \u043e\u043f\u0435\u0440\u0430\u0446\u0438\u043e\u043d\u043d\u043e\u0439 \u0441\u0438\u0441\u0442\u0435\u043c\u0435 \u0438 \u043f\u0440\u043e\u0432\u0435\u0440\u044f\u0435\u043c \u0432\u0435\u0440\u0441\u0438\u044e \u0443\u0441\u0442\u0430\u043d\u043e\u0432\u043b\u0435\u043d\u043d\u043e\u0433\u043e Docker:<\/p>\n<blockquote>\n<p><code>docker --version<\/code><\/p>\n<\/blockquote>\n<h3>\u0423\u0441\u0442\u0430\u043d\u0430\u0432\u043b\u0438\u0432\u0430\u0435\u043c Ansible<\/h3>\n<blockquote>\n<p><code>sudo apt install ansible<\/code><\/p>\n<\/blockquote>\n<p>\u0412\u0441\u0451.<\/p>\n<h3>\u0423\u0441\u0442\u0430\u043d\u043e\u0432\u043a\u0430 \u0434\u043e\u043f\u043e\u043b\u043d\u0438\u0442\u0435\u043b\u044c\u043d\u043e\u0433\u043e \u0441\u043e\u0444\u0442\u0430<\/h3>\n<p>\u0412\u044b\u0448\u0435 \u043c\u044b \u0443\u0441\u0442\u0430\u043d\u043e\u0432\u0438\u043b\u0438 \u043e\u0441\u043d\u043e\u0432\u043d\u043e\u0439 \u0441\u043e\u0444\u0442, \u043d\u043e \u0434\u043b\u044f \u043f\u043e\u043b\u043d\u043e\u0446\u0435\u043d\u043d\u043e\u0439 \u0440\u0430\u0431\u043e\u0442\u044b \u043d\u0430\u043c \u043d\u0430\u0434\u043e \u0443\u0441\u0442\u0430\u043d\u043e\u0432\u0438\u0442\u044c \u0434\u043e\u043f\u043e\u043b\u043d\u0438\u0442\u0435\u043b\u044c\u043d\u044b\u0435 \u043f\u0430\u043a\u0435\u0442\u044b.<\/p>\n<blockquote>\n<p><code>sudo apt install python3-pip<\/code><\/p>\n<p><code>pip3 install docker<\/code><\/p>\n<\/blockquote>\n<h3>\u0422\u0435\u043f\u0435\u0440\u044c \u0434\u0430\u0432\u0430\u0439\u0442\u0435 \u043f\u0438\u0441\u0430\u0442\u044c \u043a\u043e\u0434<\/h3>\n<p>\u0412\u0435\u0441\u044c \u043a\u043e\u0434, \u043a\u043e\u0442\u043e\u0440\u044b\u0439 \u0431\u0443\u0434\u0435\u0442 \u043f\u0440\u0435\u0434\u043e\u0441\u0442\u0430\u0432\u043b\u0435\u043d \u0434\u0430\u043b\u044c\u0448\u0435, \u0432\u044b \u043c\u043e\u0436\u0435\u0442\u0435 \u0441\u043a\u0430\u0447\u0430\u0442\u044c <a href=\"https:\/\/github.com\/ZeroBot-Dot\/Build-Docker-Images-with-Ansible\" rel=\"noopener noreferrer nofollow\">\u0432 \u043c\u043e\u0435\u043c \u0440\u0435\u043f\u043e\u0437\u0438\u0442\u043e\u0440\u0438\u0438 \u043d\u0430 GitHub<\/a>.<\/p>\n<p>\u0421\u043e\u0437\u0434\u0430\u0435\u043c \u043f\u0430\u043f\u043a\u0443 docker-build \u0438 \u0432 \u043d\u0435\u0439 \u0441\u043e\u0437\u0434\u0430\u0435\u043c \u0444\u0430\u0439\u043b Dockerfile, \u043e\u043d \u0431\u0443\u0434\u0435\u0442 \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u0442\u044c\u0441\u044f \u0434\u043b\u044f \u0441\u043e\u0437\u0434\u0430\u043d\u0438\u044f Docker image.<\/p>\n<p><strong>\u0421\u043e\u0434\u0435\u0440\u0436\u0438\u043c\u043e\u0435 \u0444\u0430\u0439\u043b\u0430:<\/strong><\/p>\n<blockquote>\n<p><code>FROM nginx:latest<\/p>\n<p># Default Nginx static file location<br \/># Ideally, we would edit the nginx.conf for new configuration<br \/>WORKDIR \/usr\/share\/nginx\/html<\/p>\n<p># Add all local static files to image working directory<br \/>ADD .\/ .\/<\/p>\n<p># If there was a lot of ADD COPY and RUN Steps, Bash script file is common practice<br \/># To bootstrap the image without additional layers<br \/># RUN \/bootstrap.sh<\/p>\n<p># Self explanatory<br \/>EXPOSE 8080<\/code><\/p>\n<\/blockquote>\n<p>\u0422\u0435\u043f\u0435\u0440\u044c \u0441\u043e\u0437\u0434\u0430\u0434\u0438\u043c \u0440\u044f\u0434\u043e\u043c \u0441 \u043f\u0430\u043f\u043a\u043e\u0439 docker-build \u043f\u0430\u043f\u043a\u0443 ansible-build. \u0412 \u043d\u0435\u0439 \u0441\u043e\u0437\u0434\u0430\u0435\u043c \u0444\u0430\u0439\u043b docker-image-playbook.yaml<\/p>\n<p><strong>\u0421\u043e\u0434\u0435\u0440\u0436\u0438\u043c\u043e\u0435 \u0444\u0430\u0439\u043b\u0430:<\/strong><\/p>\n<blockquote>\n<p><code>---<br \/>- name: Pull latest Nginx Image<br \/>\u00a0 hosts: localhost<br \/>\u00a0 tasks:<br \/>\u00a0\u00a0\u00a0 - name: Pull Nginx Image<br \/>\u00a0\u00a0\u00a0\u00a0\u00a0 docker_container:<br \/>\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0 name: \u00abnginx-ansible-base\u00bb<br \/>\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0 image: \u00abnginx:latest\u00bb<br \/>\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0 state: started<br \/>\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0 command: tail -f \/dev\/null<br \/>\u00a0\u00a0\u00a0 - name: Add Nginx Image to Ansible Hosts<br \/>\u00a0\u00a0\u00a0\u00a0\u00a0 add_host:<br \/>\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0 name: \u00abnginx-ansible-base\u00bb<br \/>\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0 ansible_connection: docker<br \/>\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0 ansible_ssh_user: root<br \/>- name: Configure Nginx Base Image for deploying Webserver<br \/>\u00a0 hosts: \u00abnginx-ansible-base\u00bb<br \/>\u00a0 gather_facts: false<br \/>\u00a0 tasks:<br \/>\u00a0\u00a0\u00a0 - name: Install Python3<br \/>\u00a0\u00a0\u00a0\u00a0\u00a0 raw: apt update &amp;&amp; apt upgrade -y &amp;&amp; apt install python3 -y<br \/>\u00a0\u00a0\u00a0 - name: Install Rsync<br \/>\u00a0\u00a0\u00a0\u00a0\u00a0 apt:<br \/>\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0 name: rsync<br \/>\u00a0\u00a0\u00a0 - name: Copy local configuration Files to Nginx Conf<br \/>\u00a0\u00a0\u00a0\u00a0\u00a0 synchronize:<br \/>\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0 src: .\/website\/<br \/>\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0 dest: \/usr\/share\/nginx\/html\/<br \/>\u00a0 \u00a0\u00a0- name: Ensure NGINX Is enabled<br \/>\u00a0\u00a0\u00a0\u00a0\u00a0 service:<br \/>\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0 name: nginx<br \/>\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0 enabled: yes<br \/>\u00a0\u00a0\u00a0 - name: Clean up Python 3 and Prerequisites<br \/>\u00a0\u00a0\u00a0\u00a0\u00a0 raw: apt purge python3 rsync -y<br \/>- name: Snapshot base image to create newly configured Image<br \/>\u00a0 hosts: localhost<br \/>\u00a0 tasks:<br \/>\u00a0\u00a0\u00a0 - name: Commit Docker image<br \/>\u00a0\u00a0\u00a0\u00a0\u00a0 command: docker commit \u00abnginx-ansible-base\u00bb \u00abnginx-ansible-build-demo\u00bb<br \/>- name: Clean Up Docker Containers<br \/>\u00a0 hosts: localhost<br \/>\u00a0 tasks:<br \/>\u00a0\u00a0\u00a0 - name: Remove Running Base Image<br \/>\u00a0\u00a0\u00a0\u00a0\u00a0 docker_container:<br \/>\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0 name: nginx-ansible-base<br \/>\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0 state: absent<br \/>\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0 force_kill: yes<\/code><\/p>\n<\/blockquote>\n<p>\u0412 \u044d\u0442\u043e\u043c \u0444\u0430\u0439\u043b\u0435 \u043e\u043f\u0438\u0441\u044b\u0432\u0430\u044e\u0442\u0441\u044f \u043a\u043e\u043c\u0430\u043d\u0434\u044b, \u043a\u043e\u0442\u043e\u0440\u044b\u0435 \u0431\u0443\u0434\u0435\u0442 \u0432\u044b\u043f\u043e\u043b\u043d\u044f\u0442\u044c Ansible.<\/p>\n<p>\u041f\u043e \u0444\u0430\u043a\u0442\u0443 \u0432 \u044d\u0442\u043e\u043c \u0444\u0430\u0439\u043b\u0435 \u043e\u043f\u0438\u0441\u0430\u043d\u0430 \u0441\u0431\u043e\u0440\u043a\u0430 \u043a\u043e\u043d\u0442\u0435\u0439\u043d\u0435\u0440\u0430 Docker \u043d\u0430 \u043e\u0441\u043d\u043e\u0432\u0430\u043d\u0438\u0438 \u043d\u0443\u0436\u043d\u043e\u0433\u043e \u043d\u0430\u043c \u043e\u0431\u0440\u0430\u0437\u0430, \u0443\u0441\u0442\u0430\u043d\u043e\u0432\u043a\u0430 \u0437\u0430\u0432\u0438\u0441\u0438\u043c\u043e\u0441\u0442\u0435\u0439 \u0438 \u043a\u043e\u043f\u0438\u0440\u043e\u0432\u0430\u043d\u0438\u0435 \u043d\u0435\u043e\u0431\u0445\u043e\u0434\u0438\u043c\u044b\u0445 \u0444\u0430\u0439\u043b\u043e\u0432. \u041d\u0435 \u0432\u0438\u0436\u0443 \u0441\u043c\u044b\u0441\u043b\u0430 \u043a\u043e\u043f\u0438\u0440\u043e\u0432\u0430\u0442\u044c \u0441\u044e\u0434\u0430 \u043e\u0444\u0438\u0446\u0438\u0430\u043b\u044c\u043d\u0443\u044e \u0434\u043e\u043a\u0443\u043c\u0435\u043d\u0442\u0430\u0446\u0438\u044e, \u043e\u043d\u0430 \u043c\u043e\u0436\u0435\u0442 \u043f\u043e\u0442\u0435\u0440\u044f\u0442\u044c \u0430\u043a\u0442\u0443\u0430\u043b\u044c\u043d\u043e\u0441\u0442\u044c, \u043f\u043e\u044d\u0442\u043e\u043c\u0443 \u0440\u0435\u043a\u043e\u043c\u0435\u043d\u0434\u0443\u044e \u0432\u0430\u043c \u0438\u0437\u0443\u0447\u0438\u0442\u044c \u0435\u0435 \u043d\u0430 \u043e\u0444\u0438\u0446\u0438\u0430\u043b\u044c\u043d\u043e\u043c \u0441\u0430\u0439\u0442\u0435 Ansible.<\/p>\n<p>\u0427\u0442\u043e\u0431\u044b \u0441\u043e\u0431\u0440\u0430\u0442\u044c \u043e\u0431\u0440\u0430\u0437 \u043d\u0430 \u043e\u0441\u043d\u043e\u0432\u0430\u043d\u0438\u0438 \u0442\u043e\u043b\u044c\u043a\u043e \u0447\u0442\u043e \u0441\u043e\u0437\u0434\u0430\u043d\u043d\u043e\u0433\u043e \u0444\u0430\u0439\u043b\u0430 docker-image-playbook.yaml \u0432\u0432\u043e\u0434\u0438\u043c \u0432 \u043a\u043e\u043d\u0441\u043e\u043b\u0438 \u043a\u043e\u043c\u0430\u043d\u0434\u0443 ansible-playbook docker-image-playbook.yaml<\/p>\n<p>\u0412 \u0440\u0435\u043f\u043e\u0437\u0438\u0442\u043e\u0440\u0438\u0438 \u0432\u044b \u043d\u0430\u0439\u0434\u0435\u0442\u0435 \u0435\u0449\u0435 \u0444\u0430\u0439\u043b\u044b \u043e\u0442 \u0434\u0432\u0443\u0445 html \u0448\u0430\u0431\u043b\u043e\u043d\u043e\u0432 \u0441\u0430\u0439\u0442\u043e\u0432. \u041e\u043d\u0438 \u0434\u043e\u0431\u0430\u0432\u043b\u0435\u043d\u044b \u0447\u0442\u043e\u0431\u044b \u043f\u0440\u0438 \u0437\u0430\u043f\u0443\u0441\u043a\u0435 \u043a\u043e\u043d\u0442\u0435\u0439\u043d\u0435\u0440\u0430 Docker \u0447\u0435\u0440\u0435\u0437 Dockerfile \u0438 \u0447\u0435\u0440\u0435\u0437 \u0444\u0430\u0439\u043b docker-image-playbook.yaml \u0432\u044b \u043c\u043e\u0433\u043b\u0438 \u0443\u0432\u0438\u0434\u0435\u0442\u044c \u0440\u0430\u0437\u043d\u0438\u0446\u0443 (\u0448\u0430\u0431\u043b\u043e\u043d\u044b \u043e\u0442\u043b\u0438\u0447\u0430\u044e\u0442\u0441\u044f \u0434\u0440\u0443\u0433 \u043e\u0442 \u0434\u0440\u0443\u0433\u0430).<\/p>\n<\/div>\n<\/div>\n<\/div>\n<div class=\"v-portal\" style=\"display:none;\"><\/div>\n<\/div>\n<p> <!----> <!----><br \/> \u0441\u0441\u044b\u043b\u043a\u0430 \u043d\u0430 \u043e\u0440\u0438\u0433\u0438\u043d\u0430\u043b \u0441\u0442\u0430\u0442\u044c\u0438 <a href=\"https:\/\/habr.com\/ru\/post\/672162\/\"> https:\/\/habr.com\/ru\/post\/672162\/<\/a><br \/><\/br><\/br><\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[],"tags":[],"class_list":["post-334677","post","type-post","status-publish","format-standard","hentry"],"_links":{"self":[{"href":"https:\/\/savepearlharbor.com\/index.php?rest_route=\/wp\/v2\/posts\/334677","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/savepearlharbor.com\/index.php?rest_route=\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/savepearlharbor.com\/index.php?rest_route=\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/savepearlharbor.com\/index.php?rest_route=\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/savepearlharbor.com\/index.php?rest_route=%2Fwp%2Fv2%2Fcomments&post=334677"}],"version-history":[{"count":0,"href":"https:\/\/savepearlharbor.com\/index.php?rest_route=\/wp\/v2\/posts\/334677\/revisions"}],"wp:attachment":[{"href":"https:\/\/savepearlharbor.com\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=334677"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/savepearlharbor.com\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=334677"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/savepearlharbor.com\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=334677"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}