简体   繁体   English

我的宅基地Docker容器中缺少MySQL套接字

[英]Mysql socket is missing in my homestead docker container

I have this issue with my app 我的应用程式有这个问题

SQLSTATE[HY000] [2002] Can't connect to local MySQL server through socket '/var/run/mysqld/mysqld.sock'(2) SQLSTATE [HY000] [2002]无法通过套接字'/var/run/mysqld/mysqld.sock'(2)连接到本地MySQL服务器

I'm using 2 docker containers to host my laravel 4.2 (I think :o) from this build 我正在使用2个docker容器来托管此版本的 laravel 4.2(我认为:o)

Here is my docker-compose.yml 这是我的docker-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

the first one is homesteaddocker_web_1 with php5.6 and the second one homesteaddocker_mariadb_1. 第一个是带有php5.6的homesteaddocker_web_1,第二个是homesteaddocker_mariadb_1。 I've searched for the mysql socket in homesteaddocker_web_1 and its not there but I've found it in the second container (homesteaddocker_mariadb_1) 我已经在homesteaddocker_web_1中搜索了mysql套接字,但它不在那儿,但是我在第二个容器(homesteaddocker_mariadb_1)中找到了它

So how can I fix this please. 所以,我该如何解决。

Docker containers are networked with a bridge. Docker容器通过网桥联网。

For one container to talk to another, you need to link them: https://docs.docker.com/engine/userguide/networking/ 为了使一个容器与另一个容器对话,您需要将它们链接: https : //docs.docker.com/engine/userguide/networking/

If your container needs to access network ressources on your local network, you may want to use --network='host' in your docker run command. 如果您的容器需要访问本地网络上的网络资源,则可能要在--network='host' run命令中使用--network='host'

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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