How to run docker-compose with host network?

2019-08-22 20:36发布

I was reading a, here, here, here, here, here

none of which answers my question.

What I want to do?

I have a mysql docker-compose image and want to connect to it from my ubuntu host using

localhost:3306

this does not work

it does work if I use

0.0.0.0:3306

which is not what I want to do. Why do I want to do all of that? because I have to start to work on an oooold legacy app, that has an old mysql version. Now I have mysql 8.0 on my computer and dont want to downgrade just for that one project. The legacy code has about 1000 references to localhost:3306 in it. Now I could refactor all that, create a config file etc... but better would be, if I could make it work so that localhost:3306 actually accesses my mysql docker-compose container. Is that possible? What do i have to add to my docker-compose yaml file?

my mysql docker-compose yaml file is this:

version: '3.3'
services:
  sciodb:
    container_name: sciodb
    image: mysql:5.6
    restart: always
    environment:
      MYSQL_DATABASE: 'db'
      # So you don't have to use root, but you can if you like
      MYSQL_USER: 'myuser'
      # You can use whatever password you like
      MYSQL_PASSWORD: 'test1234'
      # Password for root access
      MYSQL_ROOT_PASSWORD: 'test1234'
    ports:
      # <Port exposed> : < MySQL Port running inside container>
      - '3306:3306'
    expose:
      # Opens port 3306 on the container
      - '3306'
      # Where our data will be persisted
    volumes:
      - /home/myuser/nmyapp_db:/var/lib/mysql
      - /media/sf_vmwareshare:/var/vmwareshare

0条回答
登录 后发表回答