Deon
Deon

Reputation: 193

Docker mysql environment

I have a Dockerfile that is based FROM php:alpine and I'm trying to add mysql to the build.

FROM php:alpine

COPY test-data/ /var/www/

RUN apk add --update --no-cache \
    mysql

# Composer
RUN curl -s https://getcomposer.org/installer | php -- --install-dir=/usr/local/bin/ --filename=composer
ENV COMPOSER_ALLOW_SUPERUSER=1

WORKDIR /var/www

My problem is after successfully building, I tried and run the container with the mysql environment overrides but I cant login to mysql within the container.

$ docker run -e MYSQL_DATABASE=homestead -e MYSQL_USER=homestead -e MYSQL_PASSWORD=secret -e MYSQL_ROOT_PASSWORD=secret -ti --rm idecardo /bin/sh

Testing mysql login fails

$ mysql -uroot -p # with password "secret"

Upvotes: 0

Views: 278

Answers (1)

Anatoliy Kim
Anatoliy Kim

Reputation: 756

Since you are newbie - always try to learn by copying ready working code over and breaking down what is being done in that code.

For Docker:

  1. You can see the docker repository for mysql - https://hub.docker.com/_/mysql/ Under description section you will see links to various docker files for different MySQL versions.
  2. Take one of them as a source for your inspiration, for example the link to 8.0/Dockerfile: https://github.com/docker-library/mysql/blob/fc3e856313423dc2d6a8d74cfd6b678582090fc7/8.0/Dockerfile
  3. Notice that after mysql installation instructions in that dockerfile there is Entrypoint and CMD instructions.

In general:

Since you want php and mysql to work from docker - my advise is for you to see about docker-compose. Docker containers can be run in a variety of ways and docker-compose allows you to launch several docker containers, share some folders between them. In that scenario you would want to launch separate mysql container and separate php container, share host data folders between them and launch your code.

Also, watch some video tutorials online - they explain in details the basics of what docker is all about and how it works.

Upvotes: 1

Related Questions