Docker Community Forums

Share and learn in the Docker community.

mySQL service won't start up in container


(Skem58) #1

I created own docker image, but it seems like cannot start mysql service. logs are below. my.cnf is very simple.
Trying to use /usr/bin/mysqld_safe to start up. It might be very simple mistake, but any suggestion will be appreciate it.
.
my.cnf:
bind-address=0.0.0.0
–skip_name_resolve
–server-id
–log-bin
explicit_defults_for_timestamp=1

.
LOG:.
2016-10-02T03:25:49.513668Z 0 [Warning] InnoDB: New log files created, LSN=45790
2016-10-02T03:25:50.080962Z 0 [Warning] InnoDB: Creating foreign key constraint system tables.
2016-10-02T03:25:50.490418Z 0 [Warning] No existing UUID has been found, so we assume that this is the first time that this server has been started. Generating a new UUID: ead38701-884f-11e6-a59d-0242ac110004.
2016-10-02T03:25:50.530119Z 0 [Warning] Gtid table is not ready to be used. Table ‘mysql.gtid_executed’ cannot be opened.
2016-10-02T03:25:50.530467Z 1 [Warning] root@localhost is created with an empty password ! Please consider switching off the --initialize-insecure option.
2016-10-02T15:01:44.333939Z mysqld_safe Starting mysqld daemon with databases from /var/lib/mysql
2016-10-02T15:01:45.559382Z 0 [Warning] TIMESTAMP with implicit DEFAULT value is deprecated. Please use --explicit_defaults_for_timestamp server option (see documentation for more details).
2016-10-02T15:01:45.667597Z 0 [Note] /usr/sbin/mysqld (mysqld 5.7.15-0ubuntu0.16.04.1) starting as process 509 …
2016-10-02T15:01:46.241043Z 0 [Note] InnoDB: PUNCH HOLE support available
2016-10-02T15:01:46.241106Z 0 [Note] InnoDB: Mutexes and rw_locks use GCC atomic builtins
2016-10-02T15:01:46.241153Z 0 [Note] InnoDB: Uses event mutexes
2016-10-02T15:01:46.241173Z 0 [Note] InnoDB: GCC builtin __atomic_thread_fence() is used for memory barrier
2016-10-02T15:01:46.241192Z 0 [Note] InnoDB: Compressed tables use zlib 1.2.8
2016-10-02T15:01:46.241208Z 0 [Note] InnoDB: Using Linux native AIO
2016-10-02T15:01:46.283005Z 0 [Note] InnoDB: Number of pools: 1
2016-10-02T15:01:46.301614Z 0 [Note] InnoDB: Using CPU crc32 instructions
2016-10-02T15:01:46.336793Z 0 [Note] InnoDB: Initializing buffer pool, total size = 128M, instances = 1, chunk size = 128M
2016-10-02T15:01:46.378515Z 0 [Note] InnoDB: Completed initialization of buffer pool
2016-10-02T15:01:46.387524Z 0 [Note] InnoDB: If the mysqld execution user is authorized, page cleaner thread priority can be changed. See the man page of setpriority().
2016-10-02T15:01:46.408889Z 0 [Note] InnoDB: Highest supported file format is Barracuda.
2016-10-02T15:01:46.517756Z 0 [Note] InnoDB: Creating shared tablespace for temporary tables
2016-10-02T15:01:46.517938Z 0 [Note] InnoDB: Setting file ‘./ibtmp1’ size to 12 MB. Physically writing the file full; Please wait …
2016-10-02T15:01:47.168146Z 0 [Note] InnoDB: File ‘./ibtmp1’ size is now 12 MB.
2016-10-02T15:01:47.171086Z 0 [Note] InnoDB: 96 redo rollback segment(s) found. 96 redo rollback segment(s) are active.
2016-10-02T15:01:47.171145Z 0 [Note] InnoDB: 32 non-redo rollback segment(s) are active.
2016-10-02T15:01:47.172395Z 0 [Note] InnoDB: Waiting for purge to start
2016-10-02T15:01:47.222610Z 0 [Note] InnoDB: 5.7.15 started; log sequence number 2529638
2016-10-02T15:01:47.224062Z 0 [Note] Plugin ‘FEDERATED’ is disabled.
2016-10-02T15:01:47.224247Z 0 [Note] InnoDB: Loading buffer pool(s) from /var/lib/mysql/ib_buffer_pool
2016-10-02T15:01:47.234623Z 0 [Note] InnoDB: Buffer pool(s) load completed at 161002 15:01:47
2016-10-02T15:01:47.345070Z 0 [ERROR] unknown variable 'explicit_defults_for_timestamp=0’
2016-10-02T15:01:47.345167Z 0 [ERROR] Aborting


(Ktwalrus) #2

Check your spelling!


(Skem58) #3

:slight_smile: sorry… i should have looked too long…

but now SSL issue I think.
I am using noninteractive installation. I haven’t specified SSL, but this warning is required to resolve correct?
mysql is starting up in container, but container is not starting. keep crashing right after I started. docker logs can tell much. any other log I can look?

azureuser@MSLNXUB001:~/mysql$ docker logs thirsty_noether
=> Waiting for confirmation of MySQL service startup, trying 0/60 …
=> Waiting for confirmation of MySQL service startup, trying 1/60 …
=> Waiting for confirmation of MySQL service startup, trying 2/60 …
=> Waiting for confirmation of MySQL service startup, trying 3/60 …
2016-10-02T21:56:14.592593Z 0 [Note] Plugin ‘FEDERATED’ is disabled.
2016-10-02T21:56:14.593891Z 0 [Note] InnoDB: Loading buffer pool(s) from /var/lib/mysql/ib_buffer_pool
2016-10-02T21:56:14.631617Z 0 [Note] InnoDB: Buffer pool(s) load completed at 161002 21:56:14
2016-10-02T21:56:14.852794Z 0 [Warning] Failed to set up SSL because of the following SSL library error: SSL context is not usable without certificate and private key
2016-10-02T21:56:14.852853Z 0 [Note] Server hostname (bind-address): ‘127.0.0.1’; port: 3306
2016-10-02T21:56:14.852876Z 0 [Note] - ‘127.0.0.1’ resolves to ‘127.0.0.1’;
2016-10-02T21:56:14.852908Z 0 [Note] Server socket created on IP: ‘127.0.0.1’.
2016-10-02T21:56:14.961703Z 0 [Note] Event Scheduler: Loaded 0 events
2016-10-02T21:56:14.961884Z 0 [Note] /usr/sbin/mysqld: ready for connections.
Version: ‘5.7.15-0ubuntu0.16.04.1’ socket: ‘/var/run/mysqld/mysqld.sock’ port: 3306 (Ubuntu)


(David Maze) #4

The logs you quoted say the daemon started fine and is listening. Can you paste (a pointer to) your Dockerfile?

One “but”:

If the daemon is listening on 127.0.0.1, nothing outside the container will be able to talk to it. Set the daemon to listen on 0.0.0.0 instead, and if you need to bind to a specific interface on the host, use the appropriate form of docker run -p to do it there.


(Skem58) #5

Sorry… how can I do that? Is that can set in docker file?
my.cnf file has bind-address=0.0.0.0 already…


(Skem58) #6

Sorry here id dockerfile…
FROM ubuntu:latest

ENV locale-gen en_US.UTF-8

RUN apt-get update &&
DEBIAN_FRONTEND=noninteractive apt-get install -y mysql-server pwgen &&
rm -rf /var/lib/apt/lists/*

–Setting up default database configuration
COPY my.cnf /etc/mysql/conf.d/my.cnf
COPY charset.cnf /etc/mysql/conf.d/charset.cnf

ADD startup.sh /startup.sh

ENV MYSQL_USER=mysqladmin
MYSQL_PASS=Random
REPLICATION_MASTER=False
REPLICATION_SLAVE=False
REPLICATION_USER=replica
REPLICATION_PASS=replica

–Configure mysql port
EXPOSE 3306

VOLUME ["/storage/mysql/data", “/var/lib/mysql”]

CMD ["/bin/bash","/startup.sh"]


(Skem58) #7

I did docker event$… seems like container is dying right after start.

azureuser@MSLNXUB001:~/mysql$ docker run --name mysql-test -d -p 3306:3306 test1
cde9c26633084e391ef0ebe6f8cb3a16fda1c929b3597a696c79bd9d0f1f5868
2016-10-03T01:57:18.769706833Z container create cde9c26633084e391ef0ebe6f8cb3a16fda1c929b3597a696c79bd9d0f1f5868 (image=test1, name=mysql-test)
2016-10-03T01:57:19.078542837Z network connect 2834698af1632372ceb5e76d1fb05c7deaf58d18a478344d1607b8d38a59a43a (container=cde9c26633084e391ef0ebe6f8cb3a16fda1c929b3597a696c79bd9d0f1f5868, name=bridge, type=bridge)
2016-10-03T01:57:19.149630285Z volume mount 9d634d73497e905c124869f284911b53da657801d12b266cd81ac5425347207a (container=cde9c26633084e391ef0ebe6f8cb3a16fda1c929b3597a696c79bd9d0f1f5868, destination=/storage/mysql/data, driver=local, propagation=, read/write=true)
2016-10-03T01:57:19.149644585Z volume mount da2351edb8d2c159b0b4bd0b1dd625424e845b575a08f5662e7d37093afda660 (container=cde9c26633084e391ef0ebe6f8cb3a16fda1c929b3597a696c79bd9d0f1f5868, destination=/var/lib/mysql, driver=local, propagation=, read/write=true)
azureuser@MSLNXUB001:~/mysql$ 2016-10-03T01:57:19.427132775Z container start cde9c26633084e391ef0ebe6f8cb3a16fda1c929b3597a696c79bd9d0f1f5868 (image=test1, name=mysql-test)
2016-10-03T01:57:21.487430549Z container die cde9c26633084e391ef0ebe6f8cb3a16fda1c929b3597a696c79bd9d0f1f5868 (exitCode=0, image=test1, name=mysql-test)
2016-10-03T01:57:21.734687335Z network disconnect


(David Maze) #8

“exitCode=0” says to me that it’s completing successfully. Your startup.sh script ends with something like exec mysqld_safe "$@", right?


(Skem58) #9

Issue is for some reason If I run .usr/bin/mysqld_safe & (background process), container die right away.
If I start mysqld_safe without &, it is actually start up. Container is starting, but mysql -uroot -e “CREATE USER ‘${MYSQL_USER}’@’%’ IDENTIFIED BY ‘$PASS’” won’t be executed… like hanging… But I can get in container and can login as root.

So strange thing…

now my shell script has only this.
echo "starting mysql… "
/usr/bin/mysqld_safe &
sleep 10
mysql -uroot -e “CREATE USER ‘${MYSQL_USER}’@’%’ IDENTIFIED BY ‘$PASS’”


(David Maze) #10

That’s normal and expected behavior. A container should run a single foreground process, and when that process exits, the container will exit.

I would recommend just running the standard mysql image if that’s at all an option for you. If it’s not, at least reading through its setup (under https://github.com/docker-library/mysql) will be informative for how to do startup-time configuration.


(7275) #11

Hi I am facing the similar issue. When mysqld_safe is executed container is started but its not executing other statements which are following that statement. For example here mysql -uroot -e “CREATE USER ‘${MYSQL_USER}’@’%’ IDENTIFIED BY ‘$PASS’” won’t be executed….Any help on this would be great.