0
votes

I'm unable to connect to my dockerized webpack-dev-server from my host computer. Here's what I have so far.

1) Dockerfile documents exposed 8080 port and finishes with running the webpack-dev-server

Dockerfile:

EXPOSE 8080
CMD npm run start-dev


2) Dockerfile is built into image named 'uxframe'

Command Line:

docker build -t uxframe .


3) 'peteypablo' container is started using uxframe container. 'peteypablo' is listening to all internal IPs and publishes anything on internal port 8080 to port 8080

Command Line:

docker run --name peteypablo --rm -it -p 0.0.0.0:8080:8080 uxframe


4) Webpack Dev Server runs on port 8080 inside a docker container

package.json

"start-dev" : "webpack-dev-server --config ./config/webpack.config.dev.js --public --host 0.0.0.0 --port 8080"


5) Check to ensure 'peteypablo' container is running and port is open.

Command Line:

docker ps

Result:

CONTAINER ID        IMAGE               COMMAND                  CREATED             STATUS              PORTS                    NAMES
387751c35091        uxframe             "/bin/sh -c 'npm run…"   2 minutes ago       Up 2 minutes        0.0.0.0:8080->8080/tcp   peteypablo


6) Get IP Address of 'peteypablo' container

Command Line:

docker inspect peteypablo | grep IPAddress

Result:

        "SecondaryIPAddresses": null,
        "IPAddress": "172.17.0.2",
                "IPAddress": "172.17.0.2",


7) Try to connect to 172.17.0.2:8080 in browser.

Result:
This page isn't working.  172.17.0.2 didn't send any data.  ERR_EMPTY_RESPONSE

8) ** Connect to 'peteypablo' and run ifconfig to verify IP addresses. (For those following along, ifconfig requires you to install net-tools in your container. In my Dockerfile it was RUN apt-get install -qy net-tools )

Command Line:

docker exec -it peteypablo ifconfig

Result:

eth0      Link encap:Ethernet  HWaddr 02:42:ac:11:00:02
          inet addr:172.17.0.2  Bcast:172.17.255.255  Mask:255.255.0.0
          UP BROADCAST RUNNING MULTICAST  MTU:1500  Metric:1
          RX packets:792 errors:0 dropped:0 overruns:0 frame:0
          TX packets:773 errors:0 dropped:0 overruns:0 carrier:0
          collisions:0 txqueuelen:0
          RX bytes:157963 (154.2 KiB)  TX bytes:10865419 (10.3 MiB)

lo        Link encap:Local Loopback
          inet addr:127.0.0.1  Mask:255.0.0.0
          UP LOOPBACK RUNNING  MTU:65536  Metric:1
          RX packets:0 errors:0 dropped:0 overruns:0 frame:0
          TX packets:0 errors:0 dropped:0 overruns:0 carrier:0
          collisions:0 txqueuelen:1
          RX bytes:0 (0.0 B)  TX bytes:0 (0.0 B)


Still unable to connect to the webpack-dev-server.

1

1 Answers

0
votes

After all of this setup, I discovered I was able to connect to the webpack-dev-server using http://localhost:8080 instead of my container's IP address of http://172.17.0.2:8080.

I'm still not sure why the ip address of the docker container itself doesn't work. From what I've gathered, it seems to have to do with the virtualization needed as part of Docker for Mac.