In conclusion, Docker is popular because it has revolutionized development
Docker, and the containers it makes possible, has revolutionized the software industry and in five short years their popularity as a tool and platform has skyrocketed.
The main reason is that containers create vast economies of scale. Systems that used to require expensive, dedicated hardware resources can now share hardware with other systems. Another is that containers are self-contained and portable. If a container works on one host, it will work just as well on any other, as long as that host provides a compatible runtime.[2]
[root@localhost ~]# docker ps CONTAINER ID IMAGE COMMAND CREATED STATUS PORTS NAMES da9b17dbc337 mysql:5.7.33 "docker-entrypoint..." 11 seconds ago Up 9 seconds 0.0.0.0:3306->3306/tcp, 33060/tcp test_mysql
"0.0.0.0:3306->3306/tcp"表示本机的3306端口绑定到容器的3306端口。
利用"docker port [容器] 容器的端口号"查询容器端口是否绑定了主机的端口:
1 2 3 4
[root@localhost ~]# docker port test_mysql 3306/tcp -> 0.0.0.0:3306 [root@localhost ~]# docker port test_mysql 3307 Error: No public port '3307/tcp' published for test_mysql
[root@localhost /work/blog]# docker exec -it test_mysql bash root@b4b7c5c8ba56:/# mysql -u root -p Enter password: Welcome to the MySQL monitor. Commands end with ; or \g. Your MySQL connection id is 3 Server version: 5.7.33 MySQL Community Server (GPL)
Copyright (c) 2000, 2021, Oracle and/or its affiliates.
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>
远程连接MySQL实例(使用Navicat)
我们先查看哪些用户允许远程登录:
1 2 3 4 5 6 7 8 9 10 11 12 13
mysql> use mysql; ... mysql> select user, host from user -> ; +---------------+-----------+ | user | host | +---------------+-----------+ | root | % | | mysql.session | localhost | | mysql.sys | localhost | | root | localhost | +---------------+-----------+ 4 rows in set (0.00 sec)
[root@localhost ~]# systemctl status docker ● docker.service - Docker Application Container Engine Loaded: loaded (/usr/lib/systemd/system/docker.service; disabled; vendor preset: disabled) Active: active (running) since Sat 2021-02-20 20:26:29 CST; 17min ago Docs: http://docs.docker.com Main PID: 1834 (dockerd-current) Tasks: 24 Memory: 10.5M CGroup: /system.slice/docker.service ├─1834 /usr/bin/dockerd-current --add-runtime docker-runc=/usr/libexec/docker/docker-runc-current --default-runtime=docker-runc --exec-opt native.cgroupdrive... └─1840 /usr/bin/docker-containerd-current -l unix:///var/run/docker/libcontainerd/docker-containerd.sock --metrics-interval=0 --start-timeout 2m --state-dir ...
Feb 20 20:26:29 localhost.localdomain dockerd-current[1834]: time="2021-02-20T20:26:29.579501459+08:00" level=info msg="Daemon has completed initialization" Feb 20 20:26:29 localhost.localdomain dockerd-current[1834]: time="2021-02-20T20:26:29.579610063+08:00" level=info msg="Docker daemon" commit="0be3e21/1.13.1" g...n=1.13.1 Feb 20 20:26:29 localhost.localdomain dockerd-current[1834]: time="2021-02-20T20:26:29.583592776+08:00" level=info msg="API listen on /var/run/docker.sock" Feb 20 20:26:29 localhost.localdomain systemd[1]: Started Docker Application Container Engine. Feb 20 20:26:36 localhost.localdomain dockerd-current[1834]: 2021-02-20 12:26:36+00:00 [Note] [Entrypoint]: Entrypoint script for MySQL Server 5.7.33-1debian10 started. Feb 20 20:26:36 localhost.localdomain dockerd-current[1834]: 2021-02-20 12:26:36+00:00 [ERROR] [Entrypoint]: mysqld failed while attempting to check config Feb 20 20:26:36 localhost.localdomain dockerd-current[1834]: command was: mysqld --verbose --help Feb 20 20:26:36 localhost.localdomain dockerd-current[1834]: mysqld: Can't read dir of '/etc/mysql/conf.d/' (Errcode: 13 - Permission denied) Feb 20 20:26:36 localhost.localdomain dockerd-current[1834]: mysqld: [ERROR] Fatal error in defaults handling. Program aborted! Feb 20 20:26:36 localhost.localdomain dockerd-current[1834]: time="2021-02-20T20:26:36.709981942+08:00" level=warning msg="155b85aebe93f507939911baf4ea8e3ee18be...rgument" Hint: Some lines were ellipsized, use -l to show in full.
[root@localhost ~/docker/test_mysql/conf.d]# docker ps CONTAINER ID IMAGE COMMAND CREATED STATUS PORTS NAMES b4b7c5c8ba56 mysql:5.7.33 "docker-entrypoint..." 2 minutes ago Up 2 minutes 3306/tcp, 33060/tcp, 0.0.0.0:3307->3307/tcp test_mysql