Docker QuickStart

来自Jack's Lab
(版本间的差异)
跳转到: 导航, 搜索
(export port)
(export port)
第79行: 第79行:
 
<source lang=bash>
 
<source lang=bash>
 
comcat@aisrv:/work/api.noduino/database$ docker run -tid --name emq20 -p 1883:1883 -p 8083:8083 -p 8883:8883 -p 8084:8084 -p 18083:18083 emqttd-docker-v2.1.2
 
comcat@aisrv:/work/api.noduino/database$ docker run -tid --name emq20 -p 1883:1883 -p 8083:8083 -p 8883:8883 -p 8084:8084 -p 18083:18083 emqttd-docker-v2.1.2
docker: Error response from daemon: Conflict. The name "/emq20" is already in use by container 52df2e0d29b28509b2daae48a345cb1a44b2b5ed3ff268507cf223059d9b7921.
+
docker: Error response from daemon: Conflict. The name "/emq20" is already in use by container 52df2e0d29b28509b2daae48a345cb1a44b2b5ed3ff268507cf223059d9b
 
You have to remove (or rename) that container to be able to reuse that name..
 
You have to remove (or rename) that container to be able to reuse that name..
  

2017年8月26日 (六) 13:32的版本

目录

1 Install

$ sudo apt-get install docker.io docker-compose



2 Pull image from docker hub

comcat@aisrv:/work/api.noduino/database$ docker pull mysql/mysql-server:5.5
5.5: Pulling from mysql/mysql-server
33a3a5e469a8: Pull complete
afd5b2a51aab: Pull complete
d3fcc85ceffc: Pull complete
9c58bb63c013: Pull complete
Digest: sha256:db8aecdf439d2a5dcc509cca80deabb28a8b7370725d0c71f46957d0e257ffd6
Status: Downloaded newer image for mysql/mysql-server:5.5

comcat@aisrv:/work/api.noduino/database$ docker images
REPOSITORY             TAG                 IMAGE ID            CREATED             SIZE
emqwebhook             20170505            1a2e9eb03836        44 hours ago        33.65 MB
<none>                 <none>              3fc8aea36f2d        46 hours ago        3.994 MB
nginx                  latest              46102226f2fd        10 days ago         109.4 MB
emqttd-docker-v2.1.2   latest              a799525a9a73        2 weeks ago         34.3 MB
mysql/mysql-server     5.5                 89418f92e739        3 weeks ago         168.9 MB
alpine                 3.5                 4a415e366388        9 weeks ago         3.987 MB



3 run container

comcat@aisrv:/work/api.noduino/database$ docker run --name cos-mysql -e MYSQL_ROOT_PASSWORD=root -d mysql/mysql-server:5.5
beb67efbda72bb356a2630624eff965e89d5477cf7f596176fa45cb036d7db75

comcat@aisrv:/work/api.noduino/database$ docker exec -it cos-mysql mysql -u root -p
Enter password:
Welcome to the MySQL monitor.  Commands end with ; or \g.
Your MySQL connection id is 1
Server version: 5.5.55 MySQL Community Server (GPL)

Copyright (c) 2000, 2017, 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>

comcat@aisrv:/work/api.noduino/database$ docker exec -it cos-mysql bash



4 rm container

comcat@aisrv:/work/api.noduino/database$ docker ps -a
comcat@aisrv:/work/api.noduino/database$ docker rm beb67efbda72
beb67efbda72

comcat@aisrv:/work/api.noduino/database$ docker pull mysql/mysql-server:5.6

comcat@aisrv:/work/api.noduino/database$ docker ps -a
CONTAINER ID        IMAGE                    COMMAND                  CREATED             STATUS                        PORTS               NAMES
987ab5054b83        mysql/mysql-server:5.6   "/entrypoint.sh mysql"   18 minutes ago      Up 18 minutes                 3306/tcp            mysql
52df2e0d29b2        emqttd-docker-v2.1.2     "/opt/emqttd/start.sh"   10 days ago         Exited (137) 45 minutes ago                       emq20



5 export port

comcat@aisrv:/work/api.noduino/database$ docker run -tid --name emq20 -p 1883:1883 -p 8083:8083 -p 8883:8883 -p 8084:8084 -p 18083:18083 emqttd-docker-v2.1.2
docker: Error response from daemon: Conflict. The name "/emq20" is already in use by container 52df2e0d29b28509b2daae48a345cb1a44b2b5ed3ff268507cf223059d9b
You have to remove (or rename) that container to be able to reuse that name..

comcat@aisrv:/work/api.noduino/database$ docker start emq20
emq20



6 Passing options to the server

$ docker run --name test -e MYSQL_ROOT_PASSWORD=root -v $(pwd)/cos-db:/var/lib/mysql -d mysql/mysql-server:5.6 --explicit_defaults_for_timestamp=true



7 Mount host dir

  • place the dumped data file tempdb-xxx.sql in host dir cos-db/
  • not support the sym link
comcat@aisrv:/work/api.noduino/database$ docker run --name mysql -e MYSQL_ROOT_PASSWORD=root -v $(pwd)/cos-db:/var/lib/mysql -d mysql/mysql-server:5.6
987ab5054b83a14a2249650715353b4b9dddb0e78fcbc514ae37be975ca4c145
comcat@aisrv:/work/api.noduino/database$ docker ps
CONTAINER ID        IMAGE                    COMMAND                  CREATED             STATUS              PORTS               NAMES
987ab5054b83        mysql/mysql-server:5.6   "/entrypoint.sh mysql"   3 seconds ago       Up 2 seconds        3306/tcp            mysql

comcat@aisrv:/work/api.noduino/database$ ls cos-db
auto.cnf  ibdata1  ib_logfile0  ib_logfile1  mysql  mysql.sock  performance_schema  tempdb20170407.sql
comcat@aisrv:/work/api.noduino/database$ docker exec -it mysql bash
bash-4.2# ls /var/lib/mysql/
auto.cnf  ib_logfile0  ib_logfile1  ibdata1  mysql  mysql.sock  performance_schema  tempdb20170407.sql
bash-4.2# head /var/lib/mysql/tempdb20170407.sql
head: cannot open '/var/lib/mysql/tempdb20170407.sql' for reading: No such file or directory
bash-4.2# exit
exit
comcat@aisrv:/work/api.noduino/database$ rm cos-db/tempdb20170407.sql
comcat@aisrv:/work/api.noduino/database$ cp ../backup/tempdb20170407.sql cos-db/
comcat@aisrv:/work/api.noduino/database$ docker exec -it mysql bash
bash-4.2# head /var/lib/mysql/tempdb20170407.sql
-- MySQL dump 10.13  Distrib 5.5.49, for debian-linux-gnu (x86_64)
--
-- Host: localhost    Database: tempdb
-- ------------------------------------------------------
-- Server version   5.5.49-0ubuntu0.14.04.1

/*!40101 SET @OLD_CHARACTER_SET_CLIENT=@@CHARACTER_SET_CLIENT */;
/*!40101 SET @OLD_CHARACTER_SET_RESULTS=@@CHARACTER_SET_RESULTS */;
/*!40101 SET @OLD_COLLATION_CONNECTION=@@COLLATION_CONNECTION */;
/*!40101 SET NAMES utf8 */;



8 dump all databases

$ docker exec mysql sh -c 'exec mysqldump --all-databases -uroot -p"$MYSQL_ROOT_PASSWORD"' > all.sql



9 dump table column

$ cat cos-db/getdevid.sql
select dvid from temp where productid='NNN1234' and uploadtime>'2017-03-01 00:00:00';

$ docker exec mysql sh -c 'exec mysql -uroot -p"$MYSQL_ROOT_PASSWORD" tempdb </var/lib/mysql/getdevid.sql > /var/lib/mysql/alldevid'



10 Reference



































个人工具
名字空间

变换
操作
导航
工具箱