2

I am new to docker and docker-compose.

I have mysql running in a docker container, with two databases initialized.

I can connect to it using:

mysql --port=3306 -h192.0.0.1 -uroot -ppassword

When I run:

docker ps

04bc1d308484        container-mysql   "docker-entrypoint.sh"   2 hours ago         Up 2 hours          3306/tcp            container-mysql

My query is that now I want to connect to it from another container using

docker-compose up.

another-image:
  image: another-image
  command: /opt/start.sh
  ports:
    - "8080:8080"
  environment:
    DB_URL: container-mysql
    DB_USER: root
    DB_PASSWORD: password
  external_links:
    - container-mysql

Can someone please guide me whats missing and what else is needed.

My container-mysql has two database schema's.

Example: firstdb seconddb

1
  • I'm not sure I understood your question! but always consider checking existing open source projects who have done this before, read the code and debug.. I advise checking this docker-compose.yml file github.com/LaraDock/laradock/blob/master/docker-compose.yml Also check the DB container and it's base image to get a full overview of what's going on and how it's working. Best. Commented May 27, 2016 at 17:46

1 Answer 1

1

Ok, found the answer to it. In case anyone else comes across the same problem, just do

docker network ls

This command lists all the docker networks.

| NETWORK ID | NAME | DRIVER | SCOPE |
| ------------- | --------------- | -------- | -------- |
| c24bee6b5b8e | network-mysql | bridge | local |

Thus, a compose file demonstrating this might look like the following:

another-image:
  image: another-image
  command: /opt/start.sh
  ports:
    - "8080:8080"
  environment:
    DB_URL: container-mysql
    DB_USER: root
    DB_PASSWORD: password
  external_links:
    - container-mysql
  network_mode: network-mysql
Sign up to request clarification or add additional context in comments.

1 Comment

There is no such thing as network_mode: network-mysql in latest version. Use networks:

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.