1

I am a beginner with Docker and docker-compose for local development on my Mac. Currently, if I restart my containers, the MySql data is wiped out.

I would like to enable persistent storage for MySql local development.

Is there a way I can connect my application running inside docker container to the MySql running on my Mac Host machine?

My docker-compose.yaml file:

   mysql:
        build: ./mysql
        container_name: mysql
        environment:
            MYSQL_ROOT_PASSWORD: ******
        restart: on-failure
        ports:
            - 3306:3306

Apart from connecting docker application to MySql on local machine, is there any other way to achieve this?

2
  • Read about docker volumes, or documentation for MySQL docker image. In fact, read both. Commented Nov 3, 2017 at 5:15
  • Thanks @Cthulhu, any links would help me. Commented Nov 3, 2017 at 5:24

1 Answer 1

2

you can solve this problem by using volumes in docker-compose.yaml file. please refer the following links link1, link2. whenever a docker container runs, it will map the volume to the container. Syntax for the volumes in docker-compose.yaml is as follows:

volumes:
 - <path in host>:<path in container>
Sign up to request clarification or add additional context in comments.

4 Comments

What path does this refer to?
path in container means ..the path of data that you want to map to host path
simply copying data from container to host
That worked like a charm. Thanks. My next question is, how can I point my applications from within container to the MySql on my localhost?

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.