I
I
infoguides2017-07-15 22:44:40
Docker
infoguides, 2017-07-15 22:44:40

How to set up mysql in Docker?

I'm starting to learn docker, but a lot of things are not clear, as it happens at the beginning of the journey.
So that I understand docker correctly =)
1. Do I understand correctly: I have an Ubuntu machine and instead of deploying mysql on it, I can run a container with mysql ? How can I then use an existing database so that each time the container starts, I don’t create a dump to load, but so that all containers already work with the same database, the same users, and so on?
2. In the examples, there are a lot of options on how to do this, but so far none have started. Dockerfile or yaml file? What to end up using?
3. For example, I am developing 3 projects, all under different environments. Each project uses Apache, Mysql, PHP. I will put each project in my own container with my own set of software. Do I understand correctly that I can only run nginx on the host machine and, for example, proxy everything to different containers.
4. Where are the project sources themselves stored? In a container or on a real hard drive and the container just looks in the right directory and executes scripts from there? (eg /var/www/site1.com; /var/www/site2.com/ and so on).
Thank you!

Answer the question

In order to leave comments, you need to log in

2 answer(s)
M
Maxim Kudryavtsev, 2017-07-16
@infoguides

You start developing project #1, create a directory under it with two nested subdirectories src and db
Have you already installed docker-compose ? If not, then do so. My docker-compose.yml:

version: '3.1'

services:
  db:
    image: mariadb:10.2
    restart: on-failure
    ports:
      - "3306:3306"
    volumes:
      - ./db:/var/lib/mysql
    environment:
      MYSQL_ROOT_PASSWORD: your_root_pass_here
      MYSQL_DATABASE: db_name_here
      MYSQL_USER: db_user_here
      MYSQL_PASSWORD: user_pass_here
  nginx:
    image: nginx
    restart: on-failure
    ports:
      - "80:80"
    links:
      - wordpress:php-fpm-server
    depends_on:
      - wordpress
    volumes:
      - $HOME/DDK/nginx-default.conf:/etc/nginx/conf.d/default.conf:ro
      - ./development/src:/var/www/html:ro
  wordpress:
    image: php:5.6-fpm
    restart: on-failure
    links:
      - db:mysql
    depends_on:
      - db
    expose:
      - "9000"
      - "9900"
    volumes:
      - /mnt/bindfs/fire-cacher-dv1:/var/www/html

Next, you will have a problem, the files on your host machine will be created from the www-data user. The only sane way to fix this without strong dancing with a tambourine is bindfs. I use the following line in fstab to mount:
Created everything? OK, start docker-compose up -dand stop when finished docker-compose stop. Is the project finished? So docker-compose down -v
this is what you repeat every time you start a new project. If you have any other questions on the merits - write in the comments.

M
matperez, 2017-07-16
@matperez

1. Read the "Where to Store Data" section of the container documentation . If you want to use a common base, then the directory with it needs to be mounted in a container. How to do this is written in the documentation.
2. Dockerfile is a recipe for preparing a container, yaml is probably from docker-compose (a utility needed to run several related containers)
3. Right.
4. The folder with sources can be mounted from your machine, or copied into the container at the time of its preparation.
IMHO, if you still have a machine on Ubuntu and PHP, Mysql, Apache, Nignx, it is much easier and faster to set it all up right on the machine itself.

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question