2017-02-22 44 views
0

我有这个问题,我的应用程序Mysql的插座中缺少我的家园搬运工容器

SQLSTATE [HY000] [2002]无法通过 套接字连接到本地MySQL服务器“/ var/run中/ mysqld的/mysqld.sock'(2)

我使用2个泊坞窗集装箱主办我laravel 4.2(我认为:从这个build

这里O)是我的搬运工,compose.yml

web: 
image: shincoder/homestead:php5.6 
restart: always 
ports: 
    - "8000:80" # web 
    - "2222:22" # ssh 
    - "35729:35729" # live reload 
    - "9876:9876" # karma server 
volumes: 
    - ~/.composer:/home/homestead/.composer # composer caching 
    - ~/.gitconfig:/home/homestead/.gitconfig # Git configuration (access alias && config) 
    - ~/.ssh:/home/homestead/.ssh # Ssh keys for easy deployment inside the container 
    - ~/apps:/apps # all apps 
    - ~/apps/volumes/nginx/sites-available:/etc/nginx/sites-available # nginx sites (in case you recreate the container) 
    - ~/apps/volumes/nginx/sites-enabled:/etc/nginx/sites-enabled # nginx sites (in case you recreate the container) 
links: 
    - mariadb 
mariadb: 
    image: tutum/mariadb 
    restart: always 
    ports: 
     - "33060:3306" 
    environment: 
     MARIADB_USER: admin # cannot be changed (for info. only) 
     MARIADB_PASS: root 
    volumes: 
     - ~/apps/volumes/mysql:/var/lib/mysql # database files 

第一个是homesteaddocker_web_1,使用php5.6,第二个是homesteaddocker_mariadb_1。 我已经在homesteaddocker_web_1中搜索了mysql套接字,但它并没有在第二个容器中找到它(homesteaddocker_mariadb_1)

那么我该如何解决这个问题。

回答

0

码头集装箱与桥联网。

对于一个容器说话到另一个,你需要将它们链接: https://docs.docker.com/engine/userguide/networking/

如果你的容器需要访问你的本地网络上的网络ressources,你可能需要在泊坞窗运行命令使用--network='host'

+0

我更加困惑,我用docker-compose文件更新了我的问题。 – Getsuga

+0

我以为你试图访问你的主机上运行的数据库。所以,我的不好。 现在,你的连接字符串是什么样子?您不应该公开mariadb端口(除非您需要从外部访问),并且您应该连接到mariadb:3306 – MrE

+0

@MEI可以使用这些凭据通过mysql工作台访问我的数据库(主机:127.0.0.1,端口:33060,用户名和密码),它工作正常。我的laravel应用程序谁不能通过套接字连接到本地MySQL服务器。 – Getsuga