我想用ansible,worpdress和mysql创建一个dockerized应用。所以我在de docker_container模块中使用了一个剧本:
在vars中:
dockers:
mysql:
volume: mysql-data
volume_mount: /var/lib/mysql
volume2: '{{ docker_vols }}/mysql-cnf/my.cnf'
volume_mount2: '/etc/mysql/my.cnf'
image: mysql:latest
name: mysql
restart: always
#ports: "3306:3306"
mem: "512M"
wordpress:
volume: wp-content
volume_mount: '/var/www/html/wp-content'
volume2: wp-data
volume_mount2: '/var/www/html/'
image: wordpress:latest
name: wordpress
restart: always
ports: "8080:80"
mem: "512M"
任务:
---
- name: setup mysql
docker_container:
name: "{{ dockers.mysql.name }}"
image: "{{ dockers.mysql.image }}"
volumes:
- "{{ dockers.mysql.volume }}:{{ dockers.mysql.volume_mount }}"
state: started
restart: yes
restart_policy: "{{ dockers.mysql.restart }}"
memory: "{{ dockers.mysql.mem }}"
env:
MYSQL_ROOT_PASSWORD: "{{ MYSQL_ROOT_PASSWORD }}"
MYSQL_DATABASE: "{{ MYSQL_DATABASE }}"
MYSQL_USER: "{{ MYSQL_USER }}"
MYSQL_PASSWORD: "{{ MYSQL_PASSWORD }}"
tags: [ 'docker-run' ]
- name: setup wordpress
docker_container:
name: "{{ dockers.wordpress.name }}"
image: "{{ dockers.wordpress.image }}"
volumes:
- "{{ dockers.wordpress.volume2 }}:{{ dockers.wordpress.volume_mount2 }}"
- "{{ dockers.wordpress.volume }}:{{ dockers.wordpress.volume_mount }}"
state: started
restart: yes
restart_policy: "{{ dockers.wordpress.restart }}"
memory: "{{ dockers.wordpress.mem }}"
ports:
- "{{ dockers.wordpress.ports }}"
links:
- "mysql:mysql"
env:
#WORDPRESS_DB_HOST: "{{ WORDPRESS_DB_HOST | default(omit) }}" #also tried: "mysql:3306"
WORDPRESS_DB_USER: "{{ WORDPRESS_DB_USER }}"
WORDPRESS_DB_PASSWORD: "{{ WORDPRESS_DB_PASSWORD }}"
WORDPRESS_DB_NAME: "{{ WORDPRESS_DB_NAME }}"
tags: [ 'docker-run' ]
但是在wordpress码头工人的日志中说:
MySQL Connection Error: (2002) No route to host
AH00558: apache2: Could not reliably determine the server's fully qualified domain name, using 172.17.0.3. Set the 'ServerName' directive globally to suppress this message
我认为错误出在链接部分,但是尝试了我发现的所有表格,但仍然无法使它起作用。
答案 0 :(得分:0)
使用链接是docker link的一项旧功能。您可以创建一个泊坞窗网络,并将两个容器都连接到同一网络中,以便它们可以相互通信。
let fonts = Bundle.main.urls(forResourcesWithExtension: "ttf", subdirectory: nil)
fonts?.forEach({ url in
CTFontManagerRegisterFontsForURL(url as CFURL, .process, nil)
})
将这些行添加到每个容器中。
- name: "Create a network"
docker_network:
name: "{{ docker_network_name }}"
您的设置应该像
networks:
- name: {{ docker_network_name }}