Firman Jamal
Firman Jamal

Reputation: 123

docker-compose network error cant connect to other host

I'm new to docker and I'm having issues with connecting to my managed database cluster on the cloud services which was separated from the docker machine and network.

So recently I attempted to use docker-compose because manually writing docker run command every update is a hassle so I configure the yml file.

Whenever I use docker compose, I'm having issues connecting to the database with this error

Unhandled error event: Error: connect ENOENT %22rediss://default:[email protected]:25061%22

But if I run it on the actual docker run command with the ENV in dockerfile, then everything will work fine.

docker run -d -p 4000:4000 --restart always test

But I don't want to expose all the confidential data to the code repository with all the details on the dockerfile.

Here is my dockerfile and docker-compose

dockerfile

FROM node:14.3.0
WORKDIR /kpb
COPY package.json /kpb
RUN npm install
COPY . /kpb
CMD ["npm", "start"]

docker-compose

version: '3.8'
services:
    app:
        container_name: kibblepaw-graphql
        restart: always
        build: .
        ports: 
            - '4000:4000'
        environment: 
            - PRODUCTION="${PRODUCTION}"
            - DB_SSL="${DB_SSL}"
            - DB_CERT="${DB_CERT}"
            - DB_URL="${DB_URL}"
            - REDIS_URL="${REDIS_URL}"
            - SESSION_KEY="${SESSION_KEY}"
            - AWS_BUCKET_REGION="${AWS_BUCKET_REGION}"
            - AWS_BUCKET="${AWS_BUCKET}"
            - AWS_ACCESS_KEY_ID="${AWS_ACCESS_KEY_ID}"
            - AWS_SECRET_ACCESS_KEY="${AWS_SECRET_ACCESS_KEY}"

Upvotes: 0

Views: 629

Answers (1)

Gustavo Kawamoto
Gustavo Kawamoto

Reputation: 3067

You should not include the " for the values of your environment variables in your docker-compose.

This should work:

version: '3.8'
services:
    app:
        container_name: kibblepaw-graphql
        restart: always
        build: .
        ports: 
            - '4000:4000'
        environment: 
            - PRODUCTION=${PRODUCTION}
            - DB_SSL=${DB_SSL}
            - DB_CERT=${DB_CERT}
            - DB_URL=${DB_URL}
            - REDIS_URL=${REDIS_URL}
            - SESSION_KEY=${SESSION_KEY}
            - AWS_BUCKET_REGION=${AWS_BUCKET_REGION}
            - AWS_BUCKET=${AWS_BUCKET}
            - AWS_ACCESS_KEY_ID=${AWS_ACCESS_KEY_ID}
            - AWS_SECRET_ACCESS_KEY=${AWS_SECRET_ACCESS_KEY}

Upvotes: 1

Related Questions