目录
docker run --name mysql-container -d mysql:latest
docker run --link mysql-container:app-container -it app-image
# 创建一个用户自定义的 Docker 网络
docker network create mynetwork
# 启动 MySQL 容器并连接到 mynetwork
docker run --network mynetwork --name mysql-container -d mysql:latest
# 启动应用容器并连接到 mynetwork
docker run --network mynetwork -it app-image
3、方式三:通过docker-compose文件,其实也是创建service:
version: '3'
services:
app:
image: app-image
ports:
- "8080:80"
networks:
- mynetwork
mysql:
image: mysql:latest
environment:
MYSQL_ROOT_PASSWORD: examplepassword
networks:
- mynetwork
networks:
mynetwork: