我正在尝试从Docker Hub中提取nginx
图像,并通过以下Ansible
故事板在本地运行。
- hosts: local
connection: local
vars:
docker_info:
registry: registry.hub.docker.com
email: my@gmail.com
username: myusername
password: mypassword
tasks:
- name: log into docker hub registry
docker_login:
registry: "{{ docker_info.registry }}"
email: "{{ docker_info.email }}"
username: "{{ docker_info.username }}"
password: "{{ docker_info.password }}"
- name: Pull a container image
docker_container:
name: myngnix
image: nginx
pull: yes
state: started
和Ansible输出如下,表明其工作正常:
PLAY [local] *********************************************
TASK [Gathering Facts] ***********************************
ok: [127.0.0.1]
TASK [log into docker hub registry] **********************
ok: [127.0.0.1]
TASK [Pull a container image] ****************************
changed: [127.0.0.1]
PLAY RECAP ***********************************************
127.0.0.1 : ok=3 changed=1 unreachable=0 failed=0 skipped=0
在那之后,我浏览了http://localhost
或http://localhost:8080
,但是它不起作用。但是当我在控制台中检查容器是否正在运行时,它表明容器正在运行。
CONTAINER ID IMAGE COMMAND CREATED STATUS PORTS NAMES
22f16edfd1e8 nginx "nginx -g 'daemon of…" 9 minutes ago Up 9 minutes 80/tcp myngnix
请让我知道为什么它不起作用。非常感谢。
答案 0 :(得分:2)
您不会在主机上的任何位置发布端口8080
。试试这个:
...
- name: Pull a container image
docker_container:
name: myngnix
image: nginx
pull: yes
state: started
published_ports:
- 8080:80