简体   繁体   中英

How do I deploy a website on an nginx docker container on a remote machine using ansible playbook?

I have ansible running one of my ubuntu virtual machines on Azure. I am trying to host a website on Nginx docker container on a remote machine (host machine).

I've done everything provided o this link http://www.inanzzz.com/index.php/post/6138/setting-up-a-nginx-docker-container-on-remote-server-with-ansible

When I run the curl command it displays all the content of index.html on the terminal as output and when I try to access the website (Welcome to Nginx page) on the browser it doesn't show anything. I'm not sure what IP address to assign for the NGINX_IP variable in the docker/.env file shown in this tutorial.

Is there any other tutorial that can help me achieve what I want.

Thanks in advance.

For your issue, the problem is that you do not map the container port to the host port. So you just can access the container inside the host.

The solution is that you need to map the port in the docker-compose file like this:

version: '3'

services:
    nginx_img:
        container_name: ${COMPOSE_PROJECT_NAME}_nginx_con
        build:
            context: ./nginx
        ports:
          - "80:80"
        networks:
            public_net:
                ipv4_address: ${NGINX_IP}

networks:
    public_net:
        driver: bridge
        ipam:
            driver: default
            config:
                - subnet: ${NETWORK_SUBNET}

The docker container runs like this:

在此处输入图片说明

The last step, you need to allow the port 80 in the NSG which associated with the VM that you run the nginx. Then you can access the nginx outside the VM in the browser.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM