我有2个docker容器,它们都包含mysql数据库,我打开每个端口3305,3306。
对于3306:3306的容器,我可以通过
访问容器外的容器from sqlalchemy import create_engine
from sqlalchemy.orm import sessionmaker
from sqlalchemy.ext.declarative import declarative_base
from sqlalchemy import Column, Integer, Numeric, String
import os
cwd = os.getcwd()
import sys
sys.path.insert(0, cwd + '/vatic-docker/vatic')
#from models import *
engine = create_engine('mysql://root:1111' '@172.17.0.2:3306/vatic')
Session = sessionmaker (bind = engine)
session = Session()
Base = declarative_base()
但是我无法通过
访问3305:3306容器的mysql数据库engine = create_engine('mysql://root:1111' '@172.17.0.3:3306/vatic')
返回错误消息:
sqlalchemy.exc.OperationalError: (_mysql_exceptions.OperationalError) (2003, "Can't connect to MySQL server on '172.17.0.3' (111)")
我现在该怎么办?
答案 0 :(得分:3)
连接字符串中的端口错误
所以
@Injectable()
export class HeroService {
private heroesUrl = 'app/hero.json';
constructor (private http: Http) {}
getHeroes(): Observable<Hero[]> {
// debugger;
return this.http.get(this.heroesUrl)
.map(this.extractData)
.catch(this.handleError);
}
private extractData(res: Response) {
// http.get or http.post return the json obj
let body = res.json();
return body.data || { };
}
应该是
firebase.auth().getRedirectResult().then(result => {
var user = result.user;
if (user) {
// Save user.
}
}).catch(e => {
});
因为engine = create_engine('mysql://root:1111' '@172.17.0.3:3306/vatic')
是您在主机上公开的端口
具体而言,如果Docker主机具有IP地址engine = create_engine('mysql://root:1111@<host IP>:3305/vatic')
,则连接应为
3305
https://docs.docker.com/engine/reference/commandline/run/#publish-or-expose-port--p---expose