下载docker,安装并重启:
https://hub.docker.com/editions/community/docker-ce-desktop-windows/
如果没有安装WSL2 会有弹窗,

点击弹窗链接,下载linux内核更新包即可:
https://docs.microsoft.com/zh-cn/windows/wsl/install-win10#step-4---download-the-linux-kernel-update-package

docker中每个容器相当于是单独的服务器,访问是利用宿主机做端口监听进行的转发。所以我们可以在宿主机通过localhost访问容器,但是容器之间并不能这样访问。
具体可以在容器内通过cat etc/hosts查看到ip信息。

此时每个容器的ip是通过bridge网络进行随机分发的,因此每次重启可能出现ip的地址变化:

我们可以先自己创建网络:
docker network create <bridgename>
接着在配置启动容器时通过--network <bridgename> --network-alias <container_hostname> 来指定容器别名,例如:
--network bridge --network-alias redis_host
这样,所有关联在同一个bridgename的容器就可以直接通过定义的别名来相互访问,例如redis_host:port,无需担心ip的变化问题。
网友评论