转自:http://blog.csdn.net/daocaoren92wq/article/details/68484049$ docker pull mysql [email protected]:~$ docker pull mysql Using default tag: latest latest: Pulling from library/mysql 6d827a3ef358: Pull complete ed0929eb7dfe: Pull complete 03f348dc3b9d: Pull complete fd337761ca76: Pull complete 7e6cc16d464a: Pull complete ca3d380bc018: Pull complete 3fe11378d5c0: Pull complete 2b5dfd325645: Pull complete b54281d17fbe: Pull complete 9a5cfd2d8db6: Pull complete a371b9bf0e19: Pull complete Digest: sha256:b39e58483853ecd03160f9bfdc8d3ecb0be9071fdbbe5484d6a115677b62c84e Status: Downloaded newer image for mysql:latest [email protected]:~$ docker images REPOSITORY TAG IMAGE ID CREATED SIZE mysql_ubuntu_0.1 latest c3fb44aa3b0f 10 hours ago 130 MB mysql latest 5faba1a71ec4 8 days ago 407 MB ubuntu latest 0ef2e08ed3fa 4 weeks ago 130 MB
- $ docker run –name some-mysql -e MYSQL_ROOT_PASSWORD=my-secret-pw -d mysql:tag
–name :自定义容器名
some-MySQL:容器名字
-e :设置密码
my-secret-pw:数据库密码
-d : 后台执行
-p 端口号映射
[email protected]:~$ docker run -p 53306:3306 --name testmysql -e MYSQL_ROOT_PASSWORD=123456 -d mysql 6a38e59ef95d1a3f63a12d9c6c2ae20cf782001f25641f5159812e2a707f3f1d [email protected]:~$ docker ps -a CONTAINER ID IMAGE COMMAND CREATED STATUS PORTS NAMES 6a38e59ef95d mysql "docker-entrypoint..." 2 seconds ago Up 2 seconds 0.0.0.0:53306->3306/tcp testmysql 74d9a010c9b5 mysql "docker-entrypoint..." 24 minutes ago Up 6 minutes 3306/tcp mysql b904506516a9 mysql_ubuntu_0.1 "/bin/bash" 10 hours ago Exited (0) 10 hours ago mysql_server 9e78e89bdd4a ubuntu "/bin/bash" 11 hours ago Exited (0) 10 hours ago kickass_banach
第二个容器是不带端口映射的(-p 53306:3306),外部访问不到
第一个容器就可以通过 192.168.99.100:53306 连接数据库
- 参考
https://hub.docker.com/_/mysql/
http://blog.csdn.net/zistxym/article/details/43699029
时间: 2024-10-08 02:01:56