简体   繁体   中英

Wildfly in Docker container not starting

I'm trying to access the welcome page of Wildfly running on a Docker container in Windows 10 Pro. This is what I did:

Pulled the image:

docker pull jboss/wildfly

Run Wildfly container (this works fine, in the Wildfly log I can see it started correctly):

docker run -it -p 8080:8080 jboss/wildfly

Find the container ID:

docker ps

Inspect the IP address:

docker inspect -f "{{ .NetworkSettings.IPAddress }}" cac63ed21d78

The IP address is 172.17.0.2 , in a browser I go to http://172.17.0.2:8080/ but the browser hangs and times out. What am I missing?

UPDATE

I also tried with 127.0.0.1:8080 and it's not working either

UPDATE2

Console log:

docker --version

#Docker version 19.03.1, build 74b1e89e8a

docker run hello-world

#Hello from Docker!

docker run --detach --publish 8080:80 --name webserver nginx

#Unable to find image 'nginx:latest' locally
#latest: Pulling from library/nginx
#8ec398bc0356: Pull complete
#465560073b6f: Pull complete
#f473f9fd0a8c: Pull complete
#Digest:  sha256:b2d89d0a210398b4d1120b3e3a7672c16a4ba09c2c4a0395f18b9f7999b768f2
#Status: Downloaded newer image for nginx:latest
#c5cdb6de11240b5fe33bc424779721e1b44948797fd6ff389004d0766b71dd17

docker ps

#CONTAINER ID IMAGE COMMAND CREATED STATUS PORTS NAMES c5cdb6de1124 
#nginx "nginx -g 'daemon of" 10 minutes ago Up 10 minutes 0.0.0.0:8080->80/tcp webserver

By default, when you create a container, it does not publish any of its ports to the outside world. Network 172.17.XX is internal. If you need to bind IP address to host ip run docker container with -p flag, like that:

-p 8080:8080

Map TCP port 8080 in the container to port 8080 on the Docker host

From: https://docs.docker.com/docker-for-windows/networking/

Port forwarding works for localhost; --publish, -p, or -P all work. Ports exposed from Linux are forwarded to the host.

So it should be accessible from http://localhost:8080


If that doesn't work, then try the windows example

docker run -d -p 80:80 --name webserver nginx

Which should be accessible http://localhost:80

https://docs.docker.com/docker-for-windows/index#explore-the-application-and-run-examples


If even that fails try:

docker-machine ip default

And use http://[docker-machine-ip]:80

The key information is Docker container in Windows 10 Pro - this is very generic specification how your Docker on Windows works. There can be many options eg Docker for Windows with/without Linux containers , Docker toolbox , remote instance, ....

Generally Docker containers on Windows are running in some kind of virtual machine (Hyper-V, Virtualbox, ...), usually. So there is additional network layer, which may not be accessible directly from your Windows network namespace. But linked example runs on Linux machine, where this additional network layer doesn't exist. And that is a reason why copy/pasted Linux example doesn't work on Windows. So run container as usual and expose port 8080:

docker run -it -p 8080:8080 jboss/wildfly

But IP for access will be different and container IP can't be used, because that internal docker network is very likely not accessible from Windows. Rather try to use IP of your Windows OS. Eventually check documentation of used Docker on Windows solution and find which IP is used for exposed ports.

If you have advance windows/linux networking skills, then you may somehow route/forward port from container network namespace, through intermediate VM network layer to Windows network layer. But it can be pretty complicated.

I had a peer working on a windows system that faced the same issue. He put a lot of effort into it and just couldn't get anywhere. There's a lot of weird stuff that happens with Docker Desktop for windows it seems. We finally just installed the linux subsystem for windows and installed docker on there and it worked like a charm for him from then on. If you wish to stick to windows and you don't mind working on the linux subsystem, I suggest you go down that route. We went further than what Jan Garaj suggested and just found it to be a waste of time. Docker Desktop for Windows is meant to be a env where you completely work within it - using dev containers etc. Host-Container stuff is a pain with it.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM