4

Very similar to this question, I cannot connect to my local docker-compose container from my browser (Firefox) on Windows 10 and have been troubleshooting for some time, but I cannot seem to find the issue.

Here is my docker-compose.yml:

version: "3"
services:
    frontend:
        container_name: frontend
        build: ./frontend
        ports:
          - "3000:3000"
        working_dir: /home/node/app/
        environment:
            DEVELOPMENT: "yes"
        stdin_open: true
        volumes:
          - ./frontend:/home/node/app/
        command: bash -c "npm start & npm run build"
    my_app_django:
        container_name: my_app_django
        build: ./backend/
        environment:
        SECRET_KEY: "... not included ..."
        command: ["./rundjango.sh"]
        volumes:
            - ./backend:/code
            - media_volume:/code/media
            - static_volume:/code/static
        expose:
            - "443"
    my_app_nginx:
        container_name: my_app_nginx
        image: nginx:1.17.2-alpine
        volumes:
          - ./nginx/nginx.dev.conf:/etc/nginx/conf.d/default.conf
          - static_volume:/home/app/web/staticfiles
          - media_volume:/home/app/web/mediafiles
          - ./frontend:/home/app/frontend/
        ports:
            - "80:80"
        depends_on:
          - my_app_django
volumes:
    static_volume: 
    media_volume:

I can start the containers with docker-compose -f docker-compose.yml up -d and there are no errors when I check the logs with docker logs my_app_django or docker logs my_app_nginx. Additionally, doing docker ps shows all the containers running as they should.

The odd part about this issue is that on Linux, everything runs without issue and I can find my app on localhost at port 80. The only thing I do differently when I am on Windows is that I run a dos2unix on my .sh files to ensure that they run properly. If I omit this step, then I get many errors which leads me to believe that I have to do this.

If anyone could give guidance/advice as to what may I be doing incorrectly or missing altogether, I would be truly grateful. I am also happy to provide more details, just let me know. Thank you!

EDIT #1: As timur suggested, I did a docker run -p 80:80 -d nginx and here was the output:

Unable to find image 'nginx:latest' locally
latest: Pulling from library/nginx
bf5952930446: Pull complete
ba755a256dfe: Pull complete
c57dd87d0b93: Pull complete
d7fbf29df889: Pull complete
1f1070938ccd: Pull complete
Digest: sha256:36b74457bccb56fbf8b05f79c85569501b721d4db813b684391d63e02287c0b2
Status: Downloaded newer image for nginx:latest
19b56a66955145e4f59eefff57340b4affe5f7e0d82ad013742a60b479687c40
C:\Program Files\Docker Toolbox\docker.exe: Error response from daemon: driver failed programming external connectivity on endpoint naughty_hoover (8c7b2fa4aef964899c366e1897e38727bb7e4c38431875c5cb8456567005f368): Bind for 0.0.0.0:80 failed: port is already allocated.

This might be the cause of the error but I don't really understand what needs to be done at this point.

EDIT #2: As requested, here are my Dockerfiles (one for backend, one for frontend)

Backend Dockerfile:

FROM python:3
ENV PYTHONUNBUFFERED 1
RUN apt-get update && apt-get install -y  imagemagick libxmlsec1-dev pkg-config
RUN mkdir /code
WORKDIR /code
COPY requirements.txt /code/
RUN pip install -r requirements.txt
COPY . /code

Frontend Dockerfile:

FROM node
WORKDIR /home/node/app/
COPY . /home/node/app/
RUN npm install -g react-scripts
RUN npm install

EDIT #3: When I do docker ps, this is what I get:

CONTAINER ID        IMAGE                      COMMAND                  CREATED             STATUS              PORTS                    NAMES
0da02ad8d746        nginx:1.17.2-alpine        "nginx -g 'daemon of…"   About an hour ago   Up About an hour    0.0.0.0:80->80/tcp       my_app_nginx
070291de8362        my_app_frontend            "docker-entrypoint.s…"   About an hour ago   Up About an hour    0.0.0.0:3000->3000/tcp   frontend
2fcf551ce3fa        my_app_django              "./rundjango.sh"         12 days ago         Up About an hour    443/tcp                  my_app_django
Alerra
  • 1,479
  • 11
  • 25
  • are you using Docker Toolbox (the stack backed by VirtualBox) by any chance? – timur Aug 03 '20 at 20:44
  • Yes! I am doing all this via Docker Toolbox and running everything in the Docker Quickstart Terminal – Alerra Aug 04 '20 at 00:13
  • Then you likely need to `docker-machine ip default` (which will likely show you `192.168.99.100`) and use that ip instead of `localhost` – timur Aug 04 '20 at 01:14
  • 1
    are you sure that all your containers are running ? the command `"npm start & npm run build"` will not work you missed one & – LinPy Aug 04 '20 at 05:57
  • Please add also the Dockerfiles – Davide Pizzolato Aug 04 '20 at 11:57
  • @timur, I do get 192.168.99.100 as my default ip, but I still cannot see my app when I go to 192.168.99.100:80 on my browser – Alerra Aug 05 '20 at 17:22
  • @LinPy when I do a `docker ps`, all my apps appear here and seem to be running correctly. I also changed added another `&` to my command and the results were the same – Alerra Aug 05 '20 at 17:23
  • Do you get the same error or it's just blank? Can you try something simple like `docker run -p 80:80 -d nginx`? I suspect your host volume mappings would also have to change because of Virtual box not being so tightly integrated – timur Aug 05 '20 at 17:38
  • Also might be worth checking your VirtualBox networking setup. It's kinda hard to tell you what to look for but knowing docker machine is just a simple VM might point you somewhere – timur Aug 05 '20 at 17:45
  • @timur i edited my question after running the command you suggested. Also, when you say to check my VirtualBox setup, what specifically do you mean? – Alerra Aug 05 '20 at 18:05
  • Something (I suspect your other container from docker-compose) on your docker machine already uses port 80. Run `docker ps` to confirm. As to what settings to check, i think your setup if fine as it appears that your machine is connected and it can pull images. – timur Aug 05 '20 at 18:18
  • @timur I added the output of `docker ps` to my question. – Alerra Aug 05 '20 at 18:38
  • so container `0da02ad8d746` runs and occupies port 80. either stop it or try `docker run -p 81:80 -d nginx` - just see if `http://192.168.99.100:81` would respond at all – timur Aug 05 '20 at 19:00
  • I first tried stopping the container, but the problem persisted. So then I tried your other command, and i was able to get nginx to run on port 81. – Alerra Aug 05 '20 at 19:53
  • So then it's the issue with your container. As I hinted above, very likely to do with mounting host volumes onto container. Docker toolbox requires passing different paths relative to docker machine itself. – timur Aug 05 '20 at 21:02
  • @timur are there any links/guidance as to how to setup these paths? – Alerra Aug 05 '20 at 21:54
  • @timur thank you for your help! No rush with the answer. I really hope it works cuz you deserve the bounty – Alerra Aug 05 '20 at 22:20

1 Answers1

1

As we established you use Docker Toolbox that is backed by VirtualBox rather than default Hyper-V Docker for Windows. In this case you might think of it as a VBox VM that actually runs Docker - so all volume mounts and port mappings apply to docker machine VM, not your host. And management tools (i.e. Docker terminal and docker-compose) actually run on your host OS through MinGW.


Due to this, you don't get binding ports on localhost by default (but you can achieve this by editing VM properties in VirtualBox manually if you so desire - I just googled the second link for some picture tutorials). Suprisingly, the official documentation on this particular topic is pretty scarce - you can get a hint by looking at their examples though.

So in your case, the correct url should be http://192.168.99.100


Another thing that is different between these two solutions is volume mounts. And again, documentation sorta hints at what it should be but I can't point you a more explicit source. As you have probably noticed the terminal you use for all your docker interactions encodes paths a bit differently (I presume because of that MinGW layer) and converted paths get sent off to docker-machine - because it's Linux and would not handle windows-style paths anyway.

From here I see a couple of avenues for you to explore:

Run your project from C:\Users\...\MyProject

As the documentation states, you get c:\Users mounted into /c/Users by default. So theoretically, if you run your docker-compose from your user home folder - paths should automagically align - but since you are having this issue - you are probably running it from somewhere else.

Create another share

You also can create your own mounting mount in Virtual Box. Run pwd in your terminal and note where project root is. Then use Virtual Vox UI and create a path that would make it align with your directory tree (for example, D:\MyProject\ should become /d/MyProject.

Hopefully this will not require you to change your docker-compose.yml either

Alternatively, switch to Hyper-V Docker Desktop - and these particular issues will go away.

Bear in mind, that Hyper-V will not coexist with VirtualBox. So this option might not be available to you if you need VBox for something else.

timur
  • 14,239
  • 2
  • 11
  • 32
  • Hey! Sorry for the late reply. I have been working to get something working; I have done an extraordinary amount of reading about this, and your ideas came up in my search. For whatever reason though, I can't seem to get it to work on Docker Toolbox, so I am gonna get Windows 10 Pro so I can use Hyper-V Desktop. Thanks for your help! – Alerra Aug 10 '20 at 18:30