你好,我是Docker的新手,正在尝试在centos 7环境中设置docker。 我已使用https://docs.docker.com/install/linux/docker-ce/centos/安装了docker,然后尝试使用此https://docs.docker.com/engine/examples/dotnetcore/#build-and-run-the-docker-image使站点运行。我试图在locahost上执行wget而在这些端口上执行docker ip无效。
这是我执行的:
docker build -t aspnetapp .
docker run -it -d --name myapp aspnetapp
这是docker文件
FROM microsoft/dotnet:2.1-aspnetcore-runtime AS base
WORKDIR /app
EXPOSE 64928
EXPOSE 44340
FROM microsoft/dotnet:2.1-sdk AS build
COPY . /app
WORKDIR /app
RUN dotnet restore "TestDocker.csproj"
FROM build AS publish
RUN dotnet publish "TestDocker.csproj" -c Release -o /app
FROM base AS final
COPY --from=publish /app .
ENTRYPOINT ["dotnet", "TestDocker.dll"]
这会完美构建并运行
[root@local testSite]# docker ps
CONTAINER ID IMAGE COMMAND CREATED STATUS PORTS NAMES
b6044951aa7d aspnetapp "dotnet TestDocker.d…" 45 minutes ago Up 45 minutes 44340/tcp, 64928/tcp myapp
防火墙D:
[root@local testdocker]# firewall-cmd --list-all
public (active)
target: default
icmp-block-inversion: no
interfaces: enp9s0
sources:
services: ssh dhcpv6-client http https
ports: 44340/tcp 64928/tcp 443/tcp 80/tcp
protocols:
masquerade: no
forward-ports:
source-ports:
icmp-blocks:
rich rules:
我认为我可以直接从浏览器访问它,但是我没有运气。即使在某处有此说明,也有人可以指出我的方向。
这可能是问题
Dec 12 14:40:58 local.office firewalld[2591]: WARNING: COMMAND_FAILED: '/usr/sbin/iptables -w2 -t nat -C POSTROUTING -p tcp -s 172.17.0.2 -d 172.17.0.2 --dport 64928 -j MASQUERADE' failed: iptables: No chain/target/match by that name.
Dec 12 14:40:58 local.office firewalld[2591]: WARNING: COMMAND_FAILED: '/usr/sbin/iptables -w2 -t nat -C DOCKER -p tcp -d 0/0 --dport 80 -j DNAT --to-destination 172.17.0.2:64928 ! -i docker0' failed: iptables: No chain/target/match by that name.
Dec 12 14:42:36 local.office firewalld[2591]: WARNING: COMMAND_FAILED: '/usr/sbin/iptables -w2 -t filter -C DOCKER ! -i docker0 -o docker0 -p tcp -d 172.17.0.2 --dport 64928 -j ACCEPT' failed: iptables: Bad rule (does a matching rule exist in that chain?).
Dec 12 14:42:36 local.office firewalld[2591]: WARNING: COMMAND_FAILED: '/usr/sbin/iptables -w2 -t nat -C POSTROUTING -p tcp -s 172.17.0.2 -d 172.17.0.2 --dport 64928 -j MASQUERADE' failed: iptables: No chain/target/match by that name.
Dec 12 14:43:18 local.office firewalld[2591]: WARNING: COMMAND_FAILED: '/usr/sbin/iptables -w2 -t nat -C DOCKER -p tcp -d 0/0 --dport 64928 -j DNAT --to-destination 172.17.0.2:64928 ! -i docker0' failed: iptables: No chain/target/match by that name.
答案 0 :(得分:1)
Docker容器具有自己的网络堆栈。您需要将容器上的端口暴露给外界,并将这些端口映射到主机端口。您可以使用“ -p”标志来完成此操作。
有关详细信息,请参阅:
https://docs.docker.com/config/containers/container-networking/