Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Creating my own mysql image #214

Closed
mjdavies opened this issue Sep 15, 2016 · 4 comments
Closed

Creating my own mysql image #214

mjdavies opened this issue Sep 15, 2016 · 4 comments

Comments

@mjdavies
Copy link

mjdavies commented Sep 15, 2016

Hi Everyone

I'm pretty sure this isn't an issue with the library, more an issue with me doing something wrong.

This is what I'm trying to accomplish.

Create an image of mysql mysql:5.6.33, with the listen address set to anywhere, and then use a grant statement to give a user permission to access all the databases, from anywhere, with a password.

I'm trying to do this in a Dockerfile, but I keep bumping into problems and it's driving me nuts.

It can't be this hard, so I must be doing something stupid.

This is where I'm currently at in my Dockerfile, I've tried 'alot' of things to get it to work, no joy so far :-(

FROM mysql:5.6.33
RUN mysql_install_db --user=mysql --basedir=/usr/ --ldata=/var/lib/mysql/
ENV MYSQL_ROOT_PASSWORD bigballs
RUN sed -i -e"s/^bind-address\s*=\s*127.0.0.1/bind-address = 0.0.0.0/" /etc/mysql/my.cnf
RUN /usr/sbin/mysqld & \
    sleep 10s &&\
    echo "GRANT ALL ON *.* TO bobby@'%' IDENTIFIED BY 'bigballs' WITH GRANT OPTION; FLUSH PRIVILEGES" | mysql
EXPOSE 3306
CMD ["mysqld_safe"]
@ltangvald
Copy link
Collaborator

/var/lib/mysql is set as a volume in the mysql image, meaning the data there won't be stored in the image.
If you want database init to happen in the Dockerfile you need to put the data somewhere else.
As an example, changing to /var/lib/mysql2 (and adding a --datadir=/var/lib/mysql2 to the mysqld command) should make the image build complete successfully.
Note you'll probably lose some performance running the server against the image-internal file system.

@mjdavies
Copy link
Author

Hi @ltangvald

Thanks for getting back to me.

Would what I'm trying to achieve here be better off put into an init.sh script or something like that and then called from the Dockerfile?

@ltangvald
Copy link
Collaborator

Does it need to be stored in the image itself, or is it enough to run this init the first time the image is started?
The latter is what we normally recommend, and if it's enough then you don't need a new image, but can simply map an .sh file to the container's /docker-entrypoint-initdb.d/ directory, and it will automatically be run when the image is run the first time.

@mjdavies
Copy link
Author

mjdavies commented Nov 8, 2016

Thanks everyone, I realised I was massively overcomplicating things here.

In the end I created my own image, using this Dockerfile.

FROM mysql:5.6

RUN {
echo '[mysqld]';
echo 'character-set-server=utf8';
echo 'collation-server=utf8_general_ci';
echo '[client]';
echo 'default-character-set=utf8';
} > /etc/mysql/conf.d/charset.cnf

I've then uploaded that image to our docker repo and we call that when we create databases that we use.

I then do everything else I need to do, which isn't a lot, in the docker-compose or docker-cloud files.

Thans again.

@mjdavies mjdavies closed this as completed Nov 8, 2016
MaddieM4 added a commit to MaddieM4/mysql that referenced this issue Sep 24, 2019
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants