· 6 years ago · Jun 14, 2019, 01:15 AM
1FROM mariadb
2RUN mysql -uroot --password="test" -e "CREATE DATABASE IF NOT EXISTS mymariadb;"
3
4docker@docker-virtual-machine:~$ docker build -t tttt .
5Sending build context to Docker daemon 32.26kB
6Step 1/2 : FROM mariadb
7 ---> 2bdd97ca79d9
8Step 2/2 : RUN mysql -uroot --password="test" -e "CREATE DATABASE IF NOT EXISTS mymariadb;"
9 ---> Running in 80339dc97c2e
10ERROR 2002 (HY000): Can't connect to local MySQL server through socket '/var/run/mysqld/mysqld.sock' (2)
11The command '/bin/sh -c mysql -uroot --password="test" -e "CREATE DATABASE IF NOT EXISTS mymariadb;"' returned a non-zero code: 1
12docker@docker-virtual-machine:~$
13
14docker@docker-virtual-machine:~/test$ ls
15Dockerfile init.sql
16docker@docker-virtual-machine:~/test$ cat init.sql
17CREATE DATABASE IF NOT EXISTS mydb;
18docker@docker-virtual-machine:~/test$
19docker@docker-virtual-machine:~/test$ cat Dockerfile
20FROM mariadb
21COPY init.sql /docker-entrypoint-initdb.d/
22CMD ["mysqld"]
23docker@docker-virtual-machine:~/test$ docker build -t mydb .
24Sending build context to Docker daemon 3.072kB
25Step 1/3 : FROM mariadb
26 ---> 2bdd97ca79d9
27Step 2/3 : COPY init.sql /docker-entrypoint-initdb.d/
28 ---> 59fa0f173d93
29Step 3/3 : CMD ["mysqld"]
30 ---> Running in e605ae1fda5b
31Removing intermediate container e605ae1fda5b
32 ---> 94b98e45dc05
33Successfully built 94b98e45dc05
34Successfully tagged mydb:latest
35docker@docker-virtual-machine:~/test$ docker run -p 3306:3306/tcp -v /my/own/dat adir1:/var/lib/mysql -e MYSQL_ROOT_PASSWORD=test123 mydb
362019-01-26 17:30:21 0 [Note] mysqld (mysqld 10.3.12-MariaDB-1:10.3.12+maria~bion ic) starting as process 1 ...
372019-01-26 17:30:21 0 [Note] InnoDB: Using Linux native AIO
382019-01-26 17:30:21 0 [Note] InnoDB: Mutexes and rw_locks use GCC atomic builtin s
392019-01-26 17:30:21 0 [Note] InnoDB: Uses event mutexes
402019-01-26 17:30:21 0 [Note] InnoDB: Compressed tables use zlib 1.2.11
412019-01-26 17:30:21 0 [Note] InnoDB: Number of pools: 1
422019-01-26 17:30:21 0 [Note] InnoDB: Using SSE2 crc32 instructions
432019-01-26 17:30:21 0 [Note] InnoDB: Initializing buffer pool, total size = 256M , instances = 1, chunk size = 128M
442019-01-26 17:30:21 0 [Note] InnoDB: Completed initialization of buffer pool
452019-01-26 17:30:21 0 [Note] InnoDB: If the mysqld execution user is authorized, page cleaner thread priority can be changed. See the man page of setpriority().
462019-01-26 17:30:21 0 [Note] InnoDB: 128 out of 128 rollback segments are active .
472019-01-26 17:30:21 0 [Note] InnoDB: Creating shared tablespace for temporary ta bles
482019-01-26 17:30:21 0 [Note] InnoDB: Setting file './ibtmp1' size to 12 MB. Phys ically writing the file full; Please wait ...
492019-01-26 17:30:21 0 [Note] InnoDB: File './ibtmp1' size is now 12 MB.
502019-01-26 17:30:21 0 [Note] InnoDB: 10.3.12 started; log sequence number 163095 0; transaction id 21
512019-01-26 17:30:21 0 [Note] InnoDB: Loading buffer pool(s) from /var/lib/mysql/ ib_buffer_pool
522019-01-26 17:30:21 0 [Note] Plugin 'FEEDBACK' is disabled.
532019-01-26 17:30:21 0 [Note] InnoDB: Buffer pool(s) load completed at 190126 17: 30:21
542019-01-26 17:30:21 0 [Note] Server socket created on IP: '::'.
552019-01-26 17:30:21 0 [Warning] 'proxies_priv' entry '@% root@566af8cb98ef' igno red in --skip-name-resolve mode.
562019-01-26 17:30:21 0 [Note] Reading of all Master_info entries succeded
572019-01-26 17:30:21 0 [Note] Added new Master_info '' to hash table
582019-01-26 17:30:21 0 [Note] mysqld: ready for connections.
59Version: '10.3.12-MariaDB-1:10.3.12+maria~bionic' socket: '/var/run/mysqld/mysq ld.sock' port: 3306 mariadb.org binary distribution
60
61FROM mariadb
62COPY ./my-initial.sql /docker-entrypoint-initdb.d/
63CMD ["mysqld"]