P
P
Pavel2018-05-30 17:44:04
linux
Pavel, 2018-05-30 17:44:04

Are there examples of dockerfile somewhere, for connecting in docker-compose with the database?

There is a documize service, it consists of one binary. He needs a database to work.
I tried wrapping the service in a container:

FROM ubuntu:latest

ENV DB_USER=""
ENV DB_PASS=""
ENV DB_NAME=""

WORKDIR /documize
ADD . /documize

RUN chmod 700 ./documize-enterprise-linux-amd64

EXPOSE 5001

CMD ["sh","-c","./documize-enterprise-linux-amd64 -port=5001 -db='${DB_USER}:${DB_PASS}@tcp(localhost:3306)/${DB_NAME}' -dbtype=mysql -salt=salt"]

And made in the likeness of docker-compose.yml
version: '2'
networks:
  bridge:
    driver: bridge
services:
  web:
    image: "documize:latest"
    container_name: documize
    depends_on:
      - db
    ports:
      - "5001:5001"
    environment:
      - DB_USER=MYSQL_USER
      - DB_PASS=MYSQL_PASSWORD
      - DB_NAME=MYSQL_DATABASE
    links:
      - db
    networks:
      - bridge
  db:
    image: "mysql:5.7"
    container_name: documize_db
    volumes:
      - mysql-data:/var/lib/mysql
    ports:
      - "3306:3306"
    environment:
      - MYSQL_ROOT_PASSWORD=MYSQL_ROOT_PASSWORD 
      - MYSQL_USER=MYSQL_USER
      - MYSQL_PASSWORD=MYSQL_PASSWORD
      - MYSQL_DATABASE=MYSQL_DATABASE
    networks:
      - bridge
volumes:
  mysql-data: {}

When launched, it shows in the logs that mysql is waiting for a connection, and an error comes out from my container that the connection is not available.
How to connect them correctly? Do I need to somehow forward the network address instead of localhost?

Answer the question

In order to leave comments, you need to log in

1 answer(s)
R
Reversaidx, 2018-05-30
@rusbaron

Hi you need to pass
CMD ["sh","-c","./documize-enterprise-linux-amd64 -port=5001 -db='${DB_USER}:${DB_PASS}@tcp(localhost:3306) /${DB_NAME}' -dbtype=mysql -salt=salt"]
on
CMD ["sh","-c","./documize-enterprise-linux-amd64 -port=5001 -db='${DB_USER} :${DB_PASS}@${DB_HOST}:3306 /${DB_NAME}' -dbtype=mysql -salt=salt"]
and pass host by container name (db example), Alya DB_USER=db

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question