3

I try to run my local vue application with docker but it seem that i can't acces it with the localhost, i read that it's a windows problem but i can't solve it. i'm new in host problem and docker, i didn't success to apply the solution.

When I run

docker-compose up

Everything seem to be good, my backend is correctly connected to my database, my vue application is running, but when try too access it localy, i have an 404 error.

My structure project:

Projet
- backend
-- DockerFile
- frontend
-- DockerFile

docker-compose

Backend DockerFile

FROM node:14.17
WORKDIR /app
COPY package.json /app
RUN npm install
COPY . /app
EXPOSE 3000
CMD ["npm", "start"]

Frontend DockerFile

FROM node:lts-alpine
RUN npm install -g http-server
WORKDIR /app
COPY package*.json ./
RUN npm install
COPY . .
RUN npm run build
EXPOSE 8080
CMD [ "http-server", "dist" ]

docker-compose.yml

version: '3.8'
services:
  backend:
    build:
      context: ./Backend
      dockerfile: Dockerfile
    ports:
      - 3000:3000
    environment:
      - NODE_ENV=production
    networks:
      - backend_net
    depends_on:
      - mysqldb
  frontend:
    build:
      context: ./Frontend
      dockerfile: Dockerfile
    expose:
      - "8080"
    ports:
      - "8080:8080"
    volumes:
      - ./:/app
    networks:
      - backend_net
    depends_on:
      - mysqldb
  mysqldb:
    image: mysql:latest
    command: --default-authentication-plugin=mysql_native_password
    restart: always
    environment:
      - MYSQL_DATABASE=p07_social_network
      - MYSQL_ROOT_PASSWORD=secret
    ports:
      - 3306:3306
    expose:
      - 3306
    networks:
      - backend_net
networks:
  backend_net:
    name: p07_network

My network inspect

[
    {
        "Name": "p07_network",
        "Id": "1114316946c08de4b3e7b966517e1bcb8e6cfe4d56d0bbad9dce5b67d1dddbf1",
        "Created": "2021-05-31T19:29:59.8465635Z",
        "Scope": "local",
        "Driver": "bridge",
        "EnableIPv6": false,
        "IPAM": {
            "Driver": "default",
            "Options": null,
            "Config": [
                {
                    "Subnet": "172.28.0.0/16",
                    "Gateway": "172.28.0.1"
                }
            ]
        },
        "Internal": false,
        "Attachable": true,
        "Ingress": false,
        "ConfigFrom": {
            "Network": ""
        },
        "ConfigOnly": false,
        "Containers": {
            "2f1a7dc4151d13a374d10fd810b0155e07d1694837e57a6aacba8b97e06336a4": {
                "Name": "leonfrederic_7_07032021_mysqldb_1",
                "EndpointID": "d8480cf00d627de83f1524bb1433d4f6be262c5b9848a38ff7da85e4cefdb0df",
                "MacAddress": "02:42:ac:1c:00:02",
                "IPv4Address": "172.28.0.2/16",
                "IPv6Address": ""
            },
            "5a5f54be579538982bdbf35b1c5be60465a080bb8c8abc5584e27c64968b5dd7": {
                "Name": "leonfrederic_7_07032021_backend_1",
                "EndpointID": "43385ee40f09c497b1aaf54c691493a3d25efcb9ecfb6f08a3e08e34a6870e71",
                "MacAddress": "02:42:ac:1c:00:03",
                "IPv4Address": "172.28.0.3/16",
                "IPv6Address": ""
            },
            "e55cf7bd076f8e34901a039f5159450856b25d2186c1137d052438ded27329d3": {
                "Name": "leonfrederic_7_07032021_frontend_1",
                "EndpointID": "2712002e92f69b916dfd298ffa85cadbb9d785e35473d9825e7d65df5db84546",
                "MacAddress": "02:42:ac:1c:00:04",
                "IPv4Address": "172.28.0.4/16",
                "IPv6Address": ""
            }
        },
        "Options": {},
        "Labels": {
            "com.docker.compose.network": "p07_network",
            "com.docker.compose.project": "leonfrederic_7_07032021",
            "com.docker.compose.version": "1.29.1"
        }
    }
]

Edit: I install a virtual linux and i have the same probleme. So i'm lost ^^

2
  • remove volumes on frontend docker-compose.yml. Commented Jun 1, 2021 at 3:34
  • @jiholee Thx for your help, It's change nothing :'( Commented Jun 1, 2021 at 7:52

1 Answer 1

1

I have same problem. You need to publish server from localhost to 0.0.0.0 in Dockerfile.

Frontend

FROM mhart/alpine-node:14.16.1
WORKDIR /app
ADD . /app/


RUN rm yarn.lock
RUN yarn
RUN yarn build

ENV HOST 0.0.0.0
EXPOSE 8080

CMD [ "yarn", "start" ]

Then you can go localhost:8080/ to see the web browser result.

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.