Docker-2:network containers

docker run -d -P --name web training/webapp python app.py # -name means give the to-be-run container a name ‘web‘. -P means connect web to default network space bridge
docker network ls
docker run -itd --name=networktest ubuntu #container named networktest from image ubuntu has defaultly connected to bridge
docker network inspect bridge
docker network create -d bridge my-bridge-network #create a new network space "my-bridge-network" with network type "bridge", the other type is "overlay".
docker network ls
docker network inspect my-bridge-network
docker run -d --network=my-bridge-network --name db training/webapp #run container "db" and add it to my-bridge-network
docker inspect my-bridge-network
docker inspect --format=‘{{json .NetworkSettings.Networks}}‘ db # check the networking of container db
docker inspect --format=‘{{range .NetworkSettings.Networks}}{{.IPAddress}}{{end}}‘ db # check the networking of container db
docker run -d -P --name web training/webapp python app.py # start a container web in net space "bridge"
docker inspect --format=‘{{range .NetworkSettings.Networks}}{{.IPAddress}}{{end}}‘ web # check the networking of container web
docker exec -it db bash #run container db with bash cmd #in the container, we use ping ip_of_web, it fails for web is in bridge while db is in my-bridge-network, eventhough both web and db containers are from the SAME image
docker network connect my-bridge-network web #now connect web to my-bridge-network,Docker networking allows you to attach a container to as many networks as you like.
docker exec -it db bash #run container db with bash cmd, use ping web. succeed cause web and db are in the same network
时间: 2024-10-05 05:56:41

Docker-2:network containers的相关文章

docker - 关于network的一些理解

docker 提供给我们多种(4种)网络模式,我们可以根据自己的需求来使用.例如我们在一台主机(host)或者同一个docker engine上面运行continer的时候,我们就可以选择bridge网络模式:而当我们需要在多台host上来运行多个container来协同工作的时候,overlay模式就是我们的首选. 当我们完成docker engine的安装以后,docker会在每一个engine上面生成一个3种网络,他们是:bridge, none 还有host. 默认网络模式 - brid

Docker 启动network报错解决方案

发现一个docker容器无法远程连接,使用docker stop 也不行无法停止下来,后来发现所有的docker容器都无法连接于是重启docker看看能不能恢复正常,系统是centos 7 启动命令systemctl start docker一直卡着不动,kill掉docker的进程docker -d再次启动还是无法启动按照网上的方法是删除 rm -fr /var/lib/docker/*  所有的内容 我是docker -d 启动的我想删除docker容器我按ctrl+c应该是停止进程了但是万

Docker创建NetWork网络

1.为什么要使用NetWork 由于在Dockerfile的文件配置需要设置网络参数. 2 .常用命令 不指定网络驱动时默认创建的bridge网络 docker network create default_network 查看网络内部信息 docker network inspect default_network 列所有列表的网络 docker network ls 移除指定的网络 docker network rm default_network 原文地址:https://www.cnbl

[Docker]Docker1.9后的network

.. 声明: 本博客欢迎转发,但请保留原作者信息! 博客地址:http://blog.csdn.net/halcyonbaby 新浪微博:@寻觅神迹 内容系本人学习.研究和总结,如有雷同,实属荣幸! Docker1.9后的network 介绍与使用 1.9之后,在Docker中network从实验特性转为正式特性发布. 从命令行可以看到新增如下命令: [[email protected] system]# docker help network Usage: docker network [OP

docker offical docs:Working with Containers

enough ---------------------------------------------------------------------------------- Working with Containers - In the last section of the Docker User Guide we launched our first containers. We launched two containers using the docker run command

Docker Network Configuration 高级网络配置

Network Configuration TL;DR When Docker starts, it creates a virtual interface named docker0 on the host machine. It randomly chooses an address and subnet from the private range defined by RFC 1918 that are not in use on the host machine, and assign

Learning docker--Chapter2--Handling Docker Containers

Content: (1)    Clarifying the Docker terms (2)    Working with the Docker images and containers (3)    The Docker Hub Registry (4)    Searching the Docker images (5)    Working with an interactive container (6)    Tracking the changes inside the con

docker 使用swarm overlay网络时,报“network xx not manually attachable”错误解决

当使用swarm的overlay网络,在该网络中运行容器时报"network xx not manually attachable"的错误 docker network create -d overlay --attachable my-attachable-overlay 默认情况下使用docker network create -d overlay NET 创建的网络只能被swarm service使用,如果需要被独立的容器使用,需要添加--attachable选项 docker

VIII docker

docker: 介绍: 镜像管理: 容器管理: 网络访问: 数据管理: 镜像构建: 私有仓库: 核心技术: 生产实践: 生态圈: 一.概念: https://www.docker.com/ Docker is the world's leading software containerization platform.(build,ship,run) docker is an open platform for building,shipping and running distributed