10

Boss: here you go 3 tasks for your sprint

Days later with local server and db still not connecting on docker.

Boss: ya can we add a task on jira and get that fixed as soon as possible and see why its not working(feature doesnt work)

Me: you got it boss.

Me(in head): How am i ever going to finish my sprint for next Friday...

Comments
  • 2
    Need some help with getting that set up in docker? What's happening?
  • 2
    @alexbrooklyn my php docker container using an .env file wont connect to my mongodb in another environment. Im thinking cause its binded to 0.0.0.0 i should bind it to 127.0.0.1 in the docker compose. Any suggestions?
  • 1
    @tyler1338 First thing I'd do is throw out the .env file and switch to environment variables

    But you both run them in docker-compose right? Are they both connected in a network? Does the mongodb have an open port with expose ?

    What address do you use in the php container to connect to the mongodb container?
  • 1
    @alexbrooklyn i can connect to the container using localhost from my machine but when it comes to the other container connecting it doesnt work.
  • 6
    @tyler1338 Yep, that makes perfect sense.

    You see, a container has its own network, so using 'localhost' inside a container will point to the same container, so itself.

    Docker and docker-compoes have a great way of connecting containers and that is using the service name of the container you want to connect to.

    For example:
    ---------------------------
    networks:
    database: ~

    services:
    mongodb:
    image: ...
    network:
    - database
    [...]

    php:
    image ...
    network:
    - database
    [...]

    -----------------------

    Then you can replace 'localhost' in your php container with 'mongodb'.

    Also, I really advice to delete the .env file, it makes your container inflexible, opposed to environment variables that allow you to configure stuff from the outside.
  • 3
    @alexbrooklyn thanks a lot for the help its working!!!
  • 3
    Wow. So devrant works multiple ways. Super cool!
  • 3
    "Ill add it to the backlog and consider it in the next sprint".
Add Comment