在经历了本地化项目、办公室机器停电等一系列神操作,痛定思痛,也许借助Docker 进行软件移至和系统自动化恢复是一扇方便之门。接下来就记下Docker的学习笔记,以及常用组件的安装过程,供后来者以及自己参阅。
check os release
cat /etc/redhat-release
CentOS Linux release 7.3.1611 (Core)
create user for docker
useradd -d /usr/bmf -m bmf
passwd bmf
install docker
curl -sSL https://get.daocloud.io/docker | sh
docker -v
Docker version 18.06.0-ce, build 0ffa825
docker ps
Cannot connect to the Docker daemon at unix:///var/run/docker.sock. Is the docker daemon running?
#the exception means the docker is not running#
service docker start
Redirecting to /bin/systemctl start docker.service
install mysql5.6
docker run mysql:5.6
Unable to find image 'mysql:5.6' locally
5.6: Pulling from library/mysql
be8881be8156: Pull complete
c3995dabd1d7: Pull complete
9931fdda3586: Pull complete
bb1b6b6eff6a: Pull complete
a65f125fa718: Pull complete
62fa8db7a5dc: Pull complete
ea8988c5d951: Pull complete
0f5681d76128: Pull complete
56d3348c5742: Pull complete
b93f67de42c4: Pull complete
5adba6c10127: Pull complete
Digest:sha256:2e48836690b8416e4890c369aa********
Status: Downloaded newer image for mysql:5.6
error: database is uninitialized and password option is not specified
You need to specify one of MYSQL_ROOT_PASSWORD,MYSQL_ALLOW_EMPTY_PASSWORD and MYSQL_RANDOM_ROOT_PASSWORD
#it's said that the mysql5.6 library has been downloaded,but I used docker run command, so it will be installed, and throws the error#
docker run --name cl_mysql --restart=always -p 3306:3306 -v data-mysql:/var/lib/mysql -e MYSQL_ROOT_PASSWORD=123456 -d mysql --character-set-server=utf8mb4 --collation-server=utf8mb4_unicode_ci --lower_case_table_names=1
2018-08-22 12:17:04 0 [Note] mysqld (mysqld 5.6.41) starting as process 12 ...
2018-08-22 12:17:04 12 [Note] Plugin 'FEDERATED' is disabled.
mysqld: Table 'mysql.plugin' doesn't exist
2018-08-22 12:17:04 12 [ERROR] Can't open the mysql.plugin table. Please run mysql_upgrade to create it.
2018-08-22 12:17:04 12 [ERROR] mysqld: unknown option '--name'
2018-08-22 12:17:04 12 [ERROR] Aborting
2018-08-22 12:17:04 12 [Note] Binlog end
2018-08-22 12:17:04 12 [Note] Shutting down plugin 'MyISAM'
2018-08-22 12:17:04 12 [Note] Shutting down plugin 'CSV'
#查看服务#
docker images
REPOSITORY TAG IMAGE ID CREATED SIZE
mysql 5.6 7edb93321b06 3 weeks ago 256MB
docker ps -a
CONTAINER ID IMAGE COMMAND CREATED STATUS PORTS NAMES
09f3908c4615 mysql:5.6 "docker-entrypoint.s…" 6 minutes ago Exited (1) 6 minutes ago gallant_lumiere
ab12dbd0ddcc mysql:5.6 "docker-entrypoint.s…" 20 hours ago Exited (1) 20 hours ago focused_chatterjee
91892fa63ed6 mysql:5.6 "docker-entrypoint.s…" 20 hours ago Exited (1) 20 hours ago blissful_banach
c73e28fb4ad9 mysql:5.6 "docker-entrypoint.s…" 20 hours ago Exited (1) 20 hours ago angry_bhaskara
#delete mysql server#
docker rm container id
#发现运行上述命令依然错误,查看啦一下命令,执行如下#
docker run --name cl_mysql --restart=always -p 3306:3306 -v data-mysql:/var/lib/mysql -e MYSQL_ROOT_PASSWORD=123456 -d mysql:5.6 --character-set-server=utf8mb4 --collation-server=utf8mb4_unicode_ci --lower_case_table_names=1
83f85db8eac40f791b1bb296f893e777aae626256c0f5dc36181c133823a7713
docker ps
CONTAINER ID IMAGE COMMAND CREATED STATUS PORTS NAMES
83f85db8eac4 mysql:5.6 "docker-entrypoint.s…" 2 minutes ago Up 2 minutes 0.0.0.0:3306->3306/tcp cl_mysql
check mysql server
docker exec -it 83f8 /bin/bash
mysql -uroot -p123456 -h127.0.0.1 -P3306
mysql> show databases;
+--------------------+
| Database |
+--------------------+
| information_schema |
| mysql |
| performance_schema |
+--------------------+
params explain
--name 后面是这个镜像的名称,some-mysql
--restart=always 表示docker 重启的时候该容器也会重启,否则docker重启服
务就挂掉了
-p 3306:3306 <HOT_PORT>:<CONTAINER_PORT>表示在这个容器中使用3306端
口(第二个)映射到本机的端口号也为3306(第一个)
-v data-mysql:/var/lib/mysql <HOT_VOLUME>:<CONTAINER_DIRCTORY>
宿主机数据卷:容器目录
-d 表示使用守护进程运行,即服务挂在后台
memory limit
docker ps
CONTAINER ID NAME CPU % MEM USAGE / LIMIT MEM % NET I/O BLOCK I/O PIDS
83f85db8eac4 cl_mysql 0.03% 440.9MiB / 15.51GiB 2.78% 1.09kB / 547B 0B / 113MB 23
#default no limit, up to os total memory#
网友评论