docker環境mysql執行sql文件

#安裝docker
[root@VM_0_10_centos ~]# yum install docker

[root@VM_0_10_centos ~]# docker ps
Cannot connect to the Docker daemon at unix:///var/run/docker.sock. Is the docker daemon running?


[root@VM_0_10_centos ~]# service docker start
Redirecting to /bin/systemctl start  docker.service
[root@VM_0_10_centos ~]# docker version
Client:
 Version:         1.13.1
 API version:     1.26
 Package version: docker-1.13.1-96.gitb2f74b2.el7.centos.x86_64
 Go version:      go1.10.3
 Git commit:      b2f74b2/1.13.1
 Built:           Wed May  1 14:55:20 2019
 OS/Arch:         linux/amd64

Server:
 Version:         1.13.1
 API version:     1.26 (minimum version 1.12)
 Package version: docker-1.13.1-96.gitb2f74b2.el7.centos.x86_64
 Go version:      go1.10.3
 Git commit:      b2f74b2/1.13.1
 Built:           Wed May  1 14:55:20 2019
 OS/Arch:         linux/amd64
 Experimental:    false


[root@VM_0_10_centos ~]# docker search mysql
INDEX       NAME                                                             DESCRIPTION                                     STARS     OFFICIAL   AUTOMATED
docker.io   docker.io/mysql                                                  MySQL is a widely used, open-source relati...   8115      [OK]       
docker.io   docker.io/mariadb                                                MariaDB is a community-developed fork of M...   2753      [OK]       
docker.io   docker.io/mysql/mysql-server                                     Optimized MySQL Server Docker images. Crea...   607                  [OK]
docker.io   docker.io/zabbix/zabbix-server-mysql                             Zabbix Server with MySQL database support       191                  [OK]
docker.io   docker.io/hypriot/rpi-mysql                                      RPi-compatible Docker Image with Mysql          113                  
......



[root@VM_0_10_centos ~]# docker images
REPOSITORY          TAG                 IMAGE ID            CREATED             SIZE
[root@VM_0_10_centos ~]# docker pull mysql:5.6
Trying to pull repository docker.io/library/mysql ... 
5.6: Pulling from docker.io/library/mysql
743f2d6c1f65: Pull complete 
3f0c413ee255: Pull complete 
aef1ef8f1aac: Pull complete 
f9ee573e34cb: Pull complete 
3f237e01f153: Pull complete 
c834d5397c17: Pull complete 
167b4b0bb213: Pull complete 
8e13de731ad8: Pull complete 
0dcd497f8ff9: Pull complete 
82d36065c763: Pull complete 
f30363b0dfa6: Pull complete 
Digest: sha256:8547945d0e59b747c768e9d2bec3629ee2699837705457c3350709219b8c6ff4
Status: Downloaded newer image for docker.io/mysql:5.6
[root@VM_0_10_centos ~]# docker images
REPOSITORY          TAG                 IMAGE ID            CREATED             SIZE
docker.io/mysql     5.6                 73829d7b6139        31 hours ago        256 MB



[root@VM_0_10_centos ~]# docker run -d -p 3306:3306 --name mymysql -e MYSQL_ROOT_PASSWORD=root  docker.io/mysql
Unable to find image 'docker.io/mysql:latest' locally
Trying to pull repository docker.io/library/mysql ... 
latest: Pulling from docker.io/library/mysql
27833a3ba0a5: Pull complete 
864c283b3c4b: Pull complete 
cea281b2278b: Pull complete 
8f856c14f5af: Pull complete 
9c4f38c23b6f: Pull complete 
1b810e1751b3: Pull complete 
5479aaef3d30: Pull complete 
9667974ee097: Pull complete 
4ebb5e7ad6ac: Pull complete 
021bd5074e22: Pull complete 
cce70737c123: Pull complete 
544ff12e028f: Pull complete 
Digest: sha256:f5f78fe2054b4686da3fddb460eab0b53d04e067c977d6a02fcb5ec25375ed15
Status: Downloaded newer image for docker.io/mysql:latest
cc83848f95bfa17046a4cd0d9ae02a6e3edb2497bf35cb608deb8c9acf93ef0b
/usr/bin/docker-current: Error response from daemon: oci runtime error: container_linux.go:235: starting container process caused "process_linux.go:258: applying cgroup configuration for process caused \"Cannot set property TasksAccounting, or unknown property.\"".
[root@VM_0_10_centos ~]# docker images
REPOSITORY          TAG                 IMAGE ID            CREATED             SIZE
docker.io/mysql     5.6                 73829d7b6139        31 hours ago        256 MB
docker.io/mysql     latest              d72169616e20        2 weeks ago         443 MB
[root@VM_0_10_centos ~]# 



[root@VM_0_10_centos ~]# docker images
REPOSITORY          TAG                 IMAGE ID            CREATED             SIZE
docker.io/mysql     5.6                 73829d7b6139        31 hours ago        256 MB
docker.io/mysql     latest              d72169616e20        2 weeks ago         443 MB
[root@VM_0_10_centos ~]# docker ps
CONTAINER ID        IMAGE               COMMAND             CREATED             STATUS              PORTS               NAMES
[root@VM_0_10_centos ~]# docker rmi d72169616e20
Error response from daemon: conflict: unable to delete d72169616e20 (must be forced) - image is being used by stopped container cc83848f95bf
[root@VM_0_10_centos ~]# docker rm cc83848f95bf
cc83848f95bf
[root@VM_0_10_centos ~]# docker rmi d72169616e20
Untagged: docker.io/mysql:latest
Untagged: docker.io/mysql@sha256:f5f78fe2054b4686da3fddb460eab0b53d04e067c977d6a02fcb5ec25375ed15
Deleted: sha256:d72169616e20dc86bbf814d01652003a53388d2151d8bb0060a08696036ca34d
Deleted: sha256:676a469ed2b6dc3b714edc245a0375066a77d6f6e0650dc66d97e54ff7765813
Deleted: sha256:b4937551589869a2c683114d0ec3a98f96eb7ab4bde95640ce722cceeeea3d66
Deleted: sha256:5fdacf5035fb5490d9ceed27a50f06150a391d2c32c6c24ba93f7721626529f4
Deleted: sha256:921d18a473126d03464300a660386e013de49b57f1b183bb3b2576bcc5a18c04
Deleted: sha256:65950fd0f17f1e8ced575db9c1d2d7366712b99f1e388df02868203a55ec5905
Deleted: sha256:4e83d49f100fcd78f57b8f1844faad134d8328c5280be14d85a61ae7c7ffb981
Deleted: sha256:11f5b5e11d25f08da50ca38993f02a3194565beaa516b66970adbbffa58141e0
Deleted: sha256:2db1d1b89506973f51991ae03cb18e24f16aa2ef2b6cda4cf172b7ae4f8c15a7
Deleted: sha256:31cd685e0a1656331ab15ee8aadf47ccb1580e80baef149a8e1dfa0e7283ce64
Deleted: sha256:5f10b55a337d5bf432b0e44e22bd5730bde67251201b6890e923e3d2c641fa64
Deleted: sha256:85c59144fcd7e0cba06a9ec8e502b993bcf75035c95524aa6c92b3072828ce94
Deleted: sha256:5dacd731af1b0386ead06c8b1feff9f65d9e0bdfec032d2cd0bc03690698feda
[root@VM_0_10_centos ~]# docker images
REPOSITORY          TAG                 IMAGE ID            CREATED             SIZE
docker.io/mysql     5.6                 73829d7b6139        32 hours ago        256 MB
[root@VM_0_10_centos ~]# 



#上傳文件到docker容器
[root@server data]# docker ps
CONTAINER ID        IMAGE                 COMMAND                  CREATED             STATUS              PORTS                    NAMES
73cfe9bb6fe6        docker.io/mysql:5.6   "docker-entrypoint..."   47 hours ago        Up 5 hours          0.0.0.0:3306->3306/tcp   mymysql
[root@server data]# docker cp db_cis_227.sql 73cfe9bb6fe6:/root/

#
[root@server data]# docker exec -it 73cfe9bb6fe6  bash
root@73cfe9bb6fe6:/# mysql -u root -p
Enter password: 
Welcome to the MySQL monitor.  Commands end with ; or \g.
Your MySQL connection id is 25
Server version: 5.6.44 MySQL Community Server (GPL)

Copyright (c) 2000, 2019, Oracle and/or its affiliates. All rights reserved.

Oracle is a registered trademark of Oracle Corporation and/or its
affiliates. Other names may be trademarks of their respective
owners.

Type 'help;' or '\h' for help. Type '\c' to clear the current input statement.

mysql> source /root/dby_227.sql

mysql> show databases;
+--------------------+
| Database           |
+--------------------+
| information_schema |     |
| mysql              |
| performance_schema |
+--------------------+
6 rows in set (0.00 sec)

 

發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章