MySQL Connection in Docker container

this is driving me crazy …

I am building a simple LEMP stack with Docker on my Mac.

  • How can I save my RSA KEY in my Docker Machine?
  • Accessing localhost of a docker container from the host
  • How do I set up my Dockerfile to use cpanm to install a specific version of a Perl module?
  • Updating a container created from a custom dockerfile
  • Why does my automated build run so slowly inside a Docker container?
  • What is a simple workflow to use docker in Windows with a basic file sharing possibility?
  • This is my docker-compose file:

    nginx:
        image: tutum/nginx
        ports:
            - "3333:80"
        links:
            - phpfpm
            - db
        volumes:
            - ./nginx/default.conf:/etc/nginx/sites-available/default
            - ./nginx/default.conf:/etc/nginx/sites-enabled/default
    
            - ./logs/nginx-error.log:/var/log/nginx/error.log
            - ./logs/nginx-access.log:/var/log/nginx/access.log
    
    phpfpm:
        build: ./phpfpm
        ports:
            - "9000:9000"
        volumes:
            - ./code:/usr/share/nginx/html
    
    db:
      image: mysql
      tty: true
      restart: always
      volumes:
        - /Users/mauo/local/mysql/data:/var/lib/mysql
      ports:
        - "3308:3306"
      environment:
        MYSQL_DATABASE: 'docker'
        MYSQL_ROOT_PASSWORD: 'root'
        MYSQL_USER: 'root'
        MYSQL_ALLOW_EMPTY_PASSWORD: 'yes'
    

    Everything works fine, with exception on mysql container.

    This refuses me connection.

    This is the message on my php file inside code folder:

    (HY000/2002): Connection refused in /usr/share/nginx/html/index.php on line 2
    

    When I enter in mysql container with exec -it bash and I type ‘mysql’, the same thing, access denied for root@localhost.

    From within the container, I tried to launch ‘mysqld’ and it tells me

    2016-07-16T09:56:02.777893Z 0 [ERROR] InnoDB: Unable to lock ./ibdata1 error: 11
        2016-07-16T09:56:02.778010Z 0 [Note] InnoDB: Check that you do not already have another mysqld process using the same InnoDB data or log files.
        2016-07-16T09:56:03.779967Z 0 [ERROR] InnoDB: Unable to lock ./ibdata1 error: 11
        2016-07-16T09:56:03.780182Z 0 [Note] InnoDB: Check that you do not already have another mysqld process using the same InnoDB data or log files.
    

    Any help would be appreciated!!!!

    Thank you

    M.

  • Why the image that built by myself dont run on the kubernetes,and the pod always restart?
  • Docker creates huge image sizes
  • docker volume change force change in container
  • Docker. Send mail from host
  • Docker maven plugin NullPointerException
  • how does Docker Embedded DNS resolver work?
  • One Solution collect form web for “MySQL Connection in Docker container”

    I’m new to docker so I could be wrong.

    Have you tried root@db.
    I think some docker magic creates DNS records for your linked containers. If you manage to get root@localhost working then please let me know. I’m having the same issue.

    Docker will be the best open platform for developers and sysadmins to build, ship, and run distributed applications.