2
version: '3'
services:
  app:
    build: .
    ports:
      - "8000:8000"
    volumes:
      - .:/srv/redditaurus
    environment:
      - REDDIT_KEY=${REDDIT_KEY}
      - REDDIT_SECRET=${REDDIT_SECRET}
    links:
      - mysql:mysql
  mysql:
    image: mysql
    environment:
      MYSQL_ROOT_PASSWORD: root
    ports:
      - "3306:3306"
    # volumes:
    #   - ./mysql:/var/lib/mysql/
  nginx:
    image: nginx
    ports:
      - "80:80"

This is my docker-compose.yml. The weirdest thing is happening. I can visit localhost:8000 and get the redditaurus app without any issue. However, if I try to do the same thing with localhost:80, or localhost:3306 from a mysql terminal, I'll get access denied or ERR_EMPTY_RESPONSE.

If I try 0.0.0.0:80, I get the default nginx page, so that's okay, but why won't localhost work?

MySQL refuses to be served on either localhost or 0.0.0.0. I've tried accessing it from Sequel Pro, from inside a linked container, and from my host machine's console, and nothing can get into it. If I exec into the SQL container, I can log in just fine, so it's not a password issue.

Why can't I get to my containers normally? :(

  • 1
    Try executing `lsof -i :3306` on your host machine and post the output. And check if mysql container running with `docker ps` – Saqib Ahmed Apr 26 '18 at 16:37
  • @SaqibAhmed thanks for your response. I can confirm docker ps returns that all containers are running, supposedly on their proper ports. Why does lsof show 3307? I tried logging on that port, but it also failed. – Mansoor Syed Apr 26 '18 at 17:19
  • Just as an experiment, remove `"` in ports argument. I never used quotes with port mapping. – Saqib Ahmed Apr 26 '18 at 17:19
  • `COMMAND PID USER FD TYPE DEVICE SIZE/OFF NODE NAME com.docke 3307 mansoor 18u IPv4 0xd199c22d9e34617d 0t0 TCP *:mysql (LISTEN) com.docke 3307 mansoor 24u IPv6 0xd199c22d966b9df5 0t0 TCP localhost:mysql (LISTEN)` – Mansoor Syed Apr 26 '18 at 17:19
  • @SaqibAhmed i tried doing it without the ". It did not change anything. I try to keep them as strings to avoid problems like https://github.com/rancher/rancher/issues/550 – Mansoor Syed Apr 26 '18 at 17:23
  • Did you try 127.0.0.1 instead of localhost in SequelPro? – takacsmark Apr 27 '18 at 06:13

2 Answers2

1

You have missing some configuration properties. try this

version: '3'
services:
  app:
    build: .
    ports:
      - "8000:8000"
    volumes:
      - .:/srv/redditaurus
    environment:
      - REDDIT_KEY=${REDDIT_KEY}
      - REDDIT_SECRET=${REDDIT_SECRET}
    links:
      - mysql:mysql
  mysql:
    image: mysql
    entrypoint: ['/entrypoint.sh', '--default-authentication-plugin=mysql_native_password']
    environment:
      MYSQL_ROOT_PASSWORD: root
      MYSQL_ALLOW_EMPTY_PASSWORD: "YES"
    ports:
      - "3306:3306"
  nginx:
    image: nginx
    ports:
      - "80:80"

if you want to connect mysql via terminal. run this mysql -uroot -proot —protocol tcp

Next thing is your nginx binding with 80 is work correct.

enter image description here enter image description here

enter image description here

Problem in here is not docker-compose. It can be in your os configurations.

wthamira
  • 2,032
  • 2
  • 21
  • 40
  • This did not work. The entry point script is built into the default mysql Docker image. It doesn't need to be added. Running httpd with inplace of nginx runs fine on localhost, as does the python-tornado applicaiton. – Mansoor Syed Apr 26 '18 at 17:58
  • This is not error in docker-compose. You can see all the success messages here. It works correct in my machine – wthamira Apr 26 '18 at 18:01
  • it's the generic mysql error. `root@3640d1327a5a:/# mysql 192.168.10.192 -u root -proot mysql: [Warning] Using a password on the command line interface can be insecure. ERROR 2002 (HY000): Can't connect to local MySQL server through socket '/var/run/mysqld/mysqld.sock' (2)` – Mansoor Syed Apr 26 '18 at 18:02
  • try this. mysql -uroot -proot —protocol tcp not this mysql 192.168.10.192 -u root -proot – wthamira Apr 26 '18 at 18:04
  • run mysql -uroot -proot —protocol tcp and put the response plz – wthamira Apr 26 '18 at 18:08
  • ```mysql -uroot -proot -protocol tcp mysql: [Warning] Using a password on the command line interface can be insecure. ERROR 2002 (HY000): Can't connect to local MySQL server through socket '/tmp/mysql.sock' (2)``` – Mansoor Syed Apr 26 '18 at 18:17
  • ```CONTAINER ID IMAGE COMMAND CREATED STATUS PORTS NAMES bb194ff9719a redditaurus_app "/bin/sh -c 'python …" 2 minutes ago Up 3 minutes 0.0.0.0:8000->8000/tcp redditaurus_app_1 618e05d9141e mysql "docker-entrypoint.s…" 2 minutes ago Up 3 minutes 0.0.0.0:3306->3306/tcp redditaurus_mysql_1``` – Mansoor Syed Apr 26 '18 at 18:17
  • I think you're right in saying that it's my OS configuration, but I have no idea what it could be. It's just OSX running Docker. I haven't done any sort of customization to the config. – Mansoor Syed Apr 26 '18 at 18:18
  • is there any local mysql instance run in your machine. – wthamira Apr 26 '18 at 18:24
  • https://stackoverflow.com/questions/15450091/for-a-newbie-error-2002-hy000-cant-connect-to-local-mysql-server-through-so?utm_medium=organic&utm_source=google_rich_qa&utm_campaign=google_rich_qa – wthamira Apr 26 '18 at 18:26
  • mysql -h localhost -uroot -proot -protocol tcp – wthamira Apr 26 '18 at 18:35
1

I used mysql:5.7 tag in docker-compose, and that allowed the container to work. I guess the latest branch has some issue with my local env.

Still not sure what's up with nginx, but it's not an issue.