问题
I have docker-compose
file:
version: "3"
services:
app2:
image: kamilwit/dockerdocker_app2
container_name: app2
build:
context: ./app2
volumes:
- app2data:/data
environment:
- LOGGING_LOG-FILES-PATH=/opt/tomcat/logs
ports:
- "8000:8080"
app:
image: kamilwit/dockerdocker_app
container_name: app
build:
context: ./app
volumes:
- app1data:/data
environment:
- LOGGING_LOG-FILES-PATH=/opt/tomcat/logs
ports:
- "8001:8080"
volumes:
app1data:
app2data:
I followed the instructions from https://docs.microsoft.com/en-us/azure/container-service/dcos-swarm/container-service-swarm-walkthrough
To be exact I executed the following commands:
az group create --name myResourceGroup --location westus
az acs create --name mySwarmCluster --orchestrator-type Swarm --resource-group myResourceGroup --generate-ssh-keys --agent-count 1
then I got the output
from
az network public-ip list --resource-group myResourceGroup --query "[*].{Name:name,IPAddress:ipAddress}" -o table
Name IPAddress
-------------------------------------------------------------- --------------
swarm-agent-ip-myswarmclu-myresourcegroup-76f1d9agent-EEACED89 104.42.144.82
swarm-master-ip-myswarmclu-myresourcegroup-76f1d9mgmt-EEACED89 104.42.255.141
I connect to ssh with:
ssh -p 2200 -fNL 2375:localhost:2375 azureuser@104.42.255.141
i use:
export DOCKER_HOST=:2375
then I started my docker-compose file:
docker-compose up -d
The output of docker ps
is:
docker ps
CONTAINER ID IMAGE COMMAND CREATED STATUS PORTS NAMES
3bfff4427e44 kamilwit/dockerdocker_app "/bin/sh /data/app..." 18 minutes ago Up 8 minutes 10.0.0.5:8001->8080/tcp swarm-agent-EEACED89000001/app
c297ea34547e kamilwit/dockerdocker_app2 "/bin/sh /data/app..." 18 minutes ago Up 8 minutes 10.0.0.5:8000->8080/tcp swarm-agent-EEACED89000001/app2
However I am unable to connect to my site by ip
from agent
in the example above I tried going to
104.42.144.82:8000
and 104.42.144.82:8001/#!/registration
or even 10.0.0.5:8000
I get a time out. When i run this dockerfile locally, I connect like that to my sites:
localhost:8000
and localhost:8001/#!/registration
Tried on
az --version
azure-cli (2.0.32)
I tried opening ports in Azure
:
https://imgur.com/cjslLMN
https://imgur.com/nSAQdLS
But that did not help. I tried also opening the site from mobile phone (another network on it) did not help.
Edit:
using docker-compose
:
version: "3"
services:
app2:
image: kamilwit/dockerdocker_app2
container_name: app2
build:
context: ./app2
volumes:
- app2data:/data
environment:
- LOGGING_LOG-FILES-PATH=/opt/tomcat/logs
ports:
- "80:8080"
app:
image: kamilwit/dockerdocker_app
container_name: app
build:
context: ./app
volumes:
- app1data:/data
environment:
- LOGGING_LOG-FILES-PATH=/opt/tomcat/logs
ports:
- "8001:8080"
volumes:
app1data:
app2data:
and following the same steps from the question I can access first site on port 80, but i can not access site on port 8001. If i changed port from 8001 to 80, and leave 8000 - then i can access to the site on port 80 but no on the site on port 8000.
回答1:
First, check if your docker image works in azure, and you can open web page from swarm master server.
ssh -p 2200 azureuser@104.42.255.141 # Connect via ssh to your swarm master
sudo apt-get install lynx # Install lynx - console web browser
docker ps # check IP address of app
lynx 10.0.0.5:8000 # Open your app in lynx (using private IP address)
If page doesn't load then there is a problem with the image or your app didn't start properly.
If page loads, it means there is a problem with network infrastructure. Probably there is missing rules in load balancer for swarm agent. By default, there are open ports at 80
, 443
and 8080
. Just add new rule for 8000
, and wait a moment.
来源:https://stackoverflow.com/questions/50240972/deployment-with-docker-compose-to-azure-using-cli-gives-timeout-when-visiting-ag