Answer the question
In order to leave comments, you need to log in
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
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
docker-compose up -d
and stop when finished docker-compose stop
. Is the project finished? So docker-compose down -v
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 questionAsk a Question
731 491 924 answers to any question