Docker use local db for volume

I am new to Docker. I am trying to use docker to install Magento2 using an existing setup I already have working locally. My web is in ./ and my database is located in /var/lib/mysql. When I do docker-compose up -d my mysql container eventually stops working and the containers are not linking to the db. I have no idea why it is not working or linking.

docker-compose.yml

  • Docker's NAT table output chain rule
  • How to dockerize my new VPS server?
  • Connect RabbitMQ container from another container
  • Creating bash script from Dockerfile strips comments
  • Docker build from source fails
  • Pull, virtualize, and bash into a docker image
  • version: '2'
    
    services:
      web:
        build: .
        ports:
          - "80:80"
        volumes:
         - ./:/var/www/html
        links:
          - db
        env_file:
          - env
        depends_on:
          - db
      db:
        image: mysql:5.7.18
        volumes:
          - /var/lib/mysql:/var/lib/mysql
        env_file:
          - env
    

    Dockerfile:

    FROM alexcheng/apache2-php7
    
    MAINTAINER Fu Cheng <alexcheng1982@gmail.com>
    
    RUN a2enmod rewrite
    
    ENV MAGENTO_VERSION 2.1.6
    
    RUN curl -sS https://getcomposer.org/installer | php
    RUN mv composer.phar /usr/local/bin/composer
    RUN requirements="libpng12-dev libmcrypt-dev libmcrypt4 libcurl3-dev libfreetype6 libjpeg-turbo8 libjpeg-turbo8-dev libpng12-dev libfreetype6-dev libicu-dev libxslt1-dev" \
        && apt-get update && apt-get install -y $requirements && rm -rf /var/lib/apt/lists/* \
        && docker-php-ext-install pdo_mysql \
        && docker-php-ext-configure gd --with-freetype-dir=/usr/include/ --with-jpeg-dir=/usr/include/ \
        && docker-php-ext-install gd \
        && docker-php-ext-install mcrypt \
        && docker-php-ext-install mbstring \
        && docker-php-ext-install zip \
        && docker-php-ext-install intl \
        && docker-php-ext-install xsl \
        && docker-php-ext-install soap \
        && requirementsToRemove="libpng12-dev libmcrypt-dev libcurl3-dev libpng12-dev libfreetype6-dev libjpeg-turbo8-dev" \
        && apt-get purge --auto-remove -y $requirementsToRemove
    
    COPY ./auth.json /var/www/.composer/
    COPY ./ /var/www/html/
    RUN chsh -s /bin/bash www-data
    RUN chown -R www-data:www-data /var/www
    RUN su www-data -c "cd /var/www/html \
        && find . -type d -exec chmod 770 {} \; \
        && find . -type f -exec chmod 660 {} \; \
        && chmod u+x bin/magento"
    
    COPY ./bin/install-magento /usr/local/bin/install-magento
    RUN chmod +x /usr/local/bin/install-magento
    
    RUN echo "memory_limit=1024M" > /usr/local/etc/php/conf.d/memory-limit.ini
    
    RUN apt-get clean && rm -rf /var/lib/apt/lists/* /tmp/* /var/tmp/*
    
    WORKDIR /var/www/html
    
    VOLUME /var/www/html/var
    VOLUME /var/www/html/pub
    
    # Add cron job
    ADD crontab /etc/cron.d/magento2-cron
    RUN chmod 0644 /etc/cron.d/magento2-cron
    RUN crontab -u www-data /etc/cron.d/magento2-cron
    

    env:

    MYSQL_HOST=db
    MYSQL_ROOT_PASSWORD=mypass
    MYSQL_USER=myuser
    MYSQL_PASSWORD=mypass
    MYSQL_DATABASE=mydbname
    
    MAGENTO_LANGUAGE=en_US
    MAGENTO_TIMEZONE=America/New_York
    MAGENTO_DEFAULT_CURRENCY=USD
    MAGENTO_URL=http://<ip of vm>
    
    MAGENTO_ADMIN_FIRSTNAME=admin
    MAGENTO_ADMIN_LASTNAME=store
    MAGENTO_ADMIN_EMAIL=my@email.com
    MAGENTO_ADMIN_USERNAME=admin
    MAGENTO_ADMIN_PASSWORD=mypass
    

    docker log db

      2017-05-18T19:14:40.184335Z 0 [Note] mysqld (mysqld 5.7.18) starting as process 1 ...
    2017-05-18T19:14:40.200332Z 0 [Note] InnoDB: PUNCH HOLE support available
    2017-05-18T19:14:40.200675Z 0 [Note] InnoDB: Mutexes and rw_locks use GCC atomic builtins
    2017-05-18T19:14:40.200776Z 0 [Note] InnoDB: Uses event mutexes
    2017-05-18T19:14:40.200846Z 0 [Note] InnoDB: GCC builtin __atomic_thread_fence() is used for memory barrier
    2017-05-18T19:14:40.200873Z 0 [Note] InnoDB: Compressed tables use zlib 1.2.3
    2017-05-18T19:14:40.200917Z 0 [Note] InnoDB: Using Linux native AIO
    2017-05-18T19:14:40.206612Z 0 [Note] InnoDB: Number of pools: 1
    2017-05-18T19:14:40.208420Z 0 [Note] InnoDB: Using CPU crc32 instructions
    2017-05-18T19:14:40.217005Z 0 [Note] InnoDB: Initializing buffer pool, total size = 128M, instances = 1, chunk size = 128M
    2017-05-18T19:14:40.223891Z 0 [ERROR] InnoDB: mmap(137428992 bytes) failed; errno 12
    2017-05-18T19:14:40.224185Z 0 [ERROR] InnoDB: Cannot allocate memory for the buffer pool
    2017-05-18T19:14:40.224254Z 0 [ERROR] InnoDB: Plugin initialization aborted with error Generic error
    2017-05-18T19:14:40.224324Z 0 [ERROR] Plugin 'InnoDB' init function returned error.
    2017-05-18T19:14:40.224352Z 0 [ERROR] Plugin 'InnoDB' registration as a STORAGE ENGINE failed.
    2017-05-18T19:14:40.224398Z 0 [ERROR] Failed to initialize plugins.
    2017-05-18T19:14:40.224420Z 0 [ERROR] Aborting
    
    2017-05-18T19:14:40.224455Z 0 [Note] Binlog end
    2017-05-18T19:14:40.225243Z 0 [Note] Shutting down plugin 'MyISAM'
    2017-05-18T19:14:40.225843Z 0 [Note] Shutting down plugin 'CSV'
    2017-05-18T19:14:40.226701Z 0 [Note] mysqld: Shutdown complete
    

  • How to avoid redundancy and time loss when re-building images during development?
  • Build multiple images vs start multiple containers
  • Windows Server 2016 Dockerfile install service
  • How containerd compares to runC
  • Piping stdout on windows to docker container running linux
  • Docker image load failed on mac, error is 'invalid argument'
  • One Solution collect form web for “Docker use local db for volume”

    Docker was using all the memory had to purchase a bigger droplet

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