I am trying to set up a Django back-end, with a React front-end, both running inside a Docker container, using docker-compose to expose them at different ports (8000 for the Django app, 3000 for the React app. When I navigate to http://my_ip_address:3000/ the React app loads just fine, but when I navigate to http://my_ip_address:8000 I get a 400 Bad Request error from the server. Here is the code ->
FROM python:3.7 ENV PYTHONDONTWRITEBYTECODE 1 ENV PYTHONUNBUFFERED 1 WORKDIR /nerdrich COPY Pipfile Pipfile.lock /nerdrich/ RUN pip install pipenv && pipenv install --system COPY . /nerdrich/ EXPOSE 8000
# official node.js runtime for Docker FROM node:12 # Create and set the directory for this container WORKDIR /app/ # Install Application dependencies COPY package.json yarn.lock /app/ RUN yarn install --no-optional # Copy over the rest of the project COPY . /app/ # Set the default port for the container EXPOSE 3000 CMD yarn start
version: "3" services: web: build: ./back-end command: python /nerdrich/manage.py runserver 0.0.0.0:8000 volumes: - ./back-end:/nerdrich ports: - "8000:8000" stdin_open: true tty: true client: build: ./front-end volumes: - ./front-end:/app - /app/node_modules ports: - '3000:3000' stdin_open: true environment: - NODE_ENV=development depends_on: - "web" command: yarn start
I can provide any additional information you need, and as I said, the front-end works just fine, it is just the back-end that gives the 400 Bad Request error.
This textbox defaults to using Markdown to format your answer.
You can type !ref in this text area to quickly search our full set of tutorials, documentation & marketplace offerings and insert the link!
These answers are provided by our Community. If you find them useful, show some love by clicking the heart. If you run into issues leave a comment, or add your own answer to help others.
Join our DigitalOcean community of over a million developers for free! Get help and share knowledge in Q&A, subscribe to topics of interest, and get courses and tools that will help you grow as a developer and scale your project or business.
Click below to sign up and get $200 of credit to try our products over 60 days!