docker 实践

返回目录

1. 准备 docker 环境

2. 运行第一个容器

guojj@guojj-VirtualBox:~$ docker run hello-world

Hello from Docker!
This message shows that your installation appears to be working correctly.

To generate this message, Docker took the following steps:
1. The Docker client contacted the Docker daemon.
2. The Docker daemon pulled the "hello-world" image from the Docker Hub.
    (amd64)
3. The Docker daemon created a new container from that image which runs the
    executable that produces the output you are currently reading.
4. The Docker daemon streamed that output to the Docker client, which sent it
    to your terminal.

To try something more ambitious, you can run an Ubuntu container with:
$ docker run -it ubuntu bash

Share images, automate workflows, and more with a free Docker ID:
https://hub.docker.com/

For more examples and ideas, visit:
https://docs.docker.com/get-started/

3. docker 基本操作

4. MySQL 与容器化

4.1 拉取 MySQL

4.2 使用 MYSQL 容器

4.3 创建卷并挂载

guojj@guojj-VirtualBox:~$ docker rm $(docker ps -a -q) -f -v
bd49264cd63b
guojj@guojj-VirtualBox:~$ docker volume create mydb 
mydb
guojj@guojj-VirtualBox:~$ docker run --name mysql -e MYSQL_ROOT_PASSWORD=root -v mydb:/var/lib/mysql -d mysql:5.7
b4d53d626e6f8ca9e826aa0189486d71f0198934db2447dfa235d26017c8b574
guojj@guojj-VirtualBox:~$ docker volume ls
DRIVER              VOLUME NAME
local               15161f03dee2a55cbb0de941e6b2c97dd9dd0a9102eeec00ae9f49bd26c99d2f
local               mydb

4.4 启动客户端容器连接服务器

若显示 3306 端口已被占用,可尝试先 sudo service mysql stop

guojj@guojj-VirtualBox:~$ docker run --name myclient --link mysql:mysql -it mysql:5.7 bash
root@716d6f7ef833:/# env
...
root@716d6f7ef833:/# mysql -hmysql -P3306 -uroot -proot
mysql: [Warning] Using a password on the command line interface can be insecure.
Welcome to the MySQL monitor.  Commands end with ; or \g.
Your MySQL connection id is 2
Server version: 5.7.28 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> 

4.5 docker compose 与多容器应用自动化部署

5. docker 网络

返回目录