I use docker-compose up -d to start my services then I use docker-compose down to stop it
problem; it seems that my data is not persisted; the "${SQL_INIT}:/docker-entrypoint-initdb.d" is executed ever time
I have setup volume db_data for persistence; docker volume ls returns
local backend_mariadb-data
local docker_db_data
local docker_db_logs
here is my docker-compose
version: "3"
services:
backend:
container_name: backend
image: backend
restart: always
build: images/backend/
env_file: .env
ports:
- "8000:8000"
depends_on:
- mariadb
networks:
- app_network
mariadb:
container_name: mariadb
image: "mariadb:${MARIADB_VERSION}"
restart: 'always'
env_file: .env
volumes:
- "${SQL_INIT}:/docker-entrypoint-initdb.d"
- "db_data:${MARIADB_DATA_DIR}"
- "db_logs:${MARIADB_LOG_DIR}"
environment:
MYSQL_ROOT_PASSWORD: "${MYSQL_ROOT_PASSWORD}"
MYSQL_DATABASE: "${MYSQL_DATABASE}"
MYSQL_USER: "${MYSQL_USER}"
MYSQL_PASSWORD: "${MYSQL_PASSWORD}"
ports:
- "3306:3306"
networks:
- app_network
volumes:
db_data:
db_logs:
networks:
app_network:
with .env file
MARIADB_VERSION="latest"
MARIADB_DATA_DIR="/var/database/mariadb"
MARIADB_LOG_DIR="/var/logs/mariadb"
MYSQL_DATABASE="app"
MYSQL_USER="app"
MYSQL_PASSWORD="password"
MYSQL_ROOT_PASSWORD="password"
SQL_INIT="./database/dev"
Remove quotes in env file. Docker-Compose treats them as part of the value.
See last Bulletpoint
Besides that the default path for the data is /var/lib/mysql and for logging is /var/log/mysql (but disabled on default)
Related
I am running Flask and MySQL using docker-compose.yaml.
Although I have specified a volume, the volume has not been created.
Why is this?
docker-compose.yaml
version: '3'
services:
api:
build: python
container_name: api_server_flask
ports:
- "5000:5000"
tty: true
environment:
TZ: Asia/Tokyo
FLASK_APP: app.py
depends_on:
- db
networks:
- app_flask
db:
build: mysql
container_name: db_server_flask
ports:
- '3306:3306'
environment:
MYSQL_ROOT_PASSWORD: pass
MYSQL_DATABASE: testdb
TZ: Asia/Tokyo
volumes:
- ./db-flask-data/:/var/lib/mysql
command: mysqld
networks:
- app_flask
volumes:
db-flask-data:
networks:
app_flask:
driver: bridge
You need to remove the relative path as follows:
volumes:
- db-flask-data/:/var/lib/mysql
It is explained here: https://docs.docker.com/storage/volumes/#use-a-volume-with-docker-compose
Actually, you are creating a named volume under /var/lib/docker/volumes/db-flask-data when you are specifying the following command:
volumes:
db-flask-data:
i've installed docker (windows 10) with wsl2 (ubuntu distro) and added my docker-compose.yml
version: '3'
services:
web:
image: nginx:1.20.1
container_name: web
restart: always
ports:
- "80:80"
volumes:
- ./nginx.d.conf:/etc/nginx/conf.d/nginx.conf
- ./nginx.conf:/etc/nginx/nginx.conf
- ./www/my-app:/app
php:
build:
context: .
dockerfile: myphp.dockerFile
container_name: php
restart: always
depends_on:
- web
volumes:
- ./www/my-app:/app
mysql:
image: mariadb:10.3.28
container_name: mysql
restart: always
depends_on:
- php
environment:
MYSQL_ROOT_PASSWORD: '******'
MYSQL_USER: 'root'
MYSQL_PASSWORD: '******'
MYSQL_DATABASE: 'my-database'
command: ["--default-authentication-plugin=mysql_native_password"]
volumes:
- mysqldata:/var/lib/mysql
- ./my.cnf:/etc/mysql/my.cnf
ports:
- 3306:3306
cache:
image: redis:5.0.3
container_name: cache
restart: always
ports:
- 6379:6379
networks:
- my-network
volumes:
- ./cache:/cache
volumes:
mysqldata: {}
networks:
my-network:
driver: "bridge"
So my symfony code is in the /www/my-app window's folder. This includes the /www/my-app/vendor too.
My application is running extremely slow (50-70 seconds). If i'm correct it's because the vendor folder is huge (80MB) and docker creates an image of it every time. Other discussions mentioned that vendor folder sould be moved into a new volume, and here i'm stuck with it. How to move and mount that in this case, and how should the docker-compose.yml look like after it?
i have a problem with docker container.
That's my docker-compose file with 5 services
version: '3'
networks:
laravel:
services:
nginx:
image: nginx:stable-alpine
container_name: nginx
ports:
- "8088:80"
volumes:
- ./src:/var/www/html
- ./nginx/default.conf:/etc/nginx/conf.d/default.conf
depends_on:
- mysql
- php
networks:
- laravel
mysql:
image: mysql:5.7.22
container_name: mysql
restart: unless-stopped
tty: true
ports:
- "4306:3306"
environment:
MYSQL_DATABASE: homestead
MYSQL_USER: homestead
MYSQL_PASSWORD: secret
MYSQL_ROOT_PASSWORD: secret
SERVICE_TAGS: dev
SERVICE_NAME: mysql
networks:
- laravel
php:
build:
context: .
dockerfile: Dockerfile
container_name: php
volumes:
- ./src:/var/www/html
ports:
- "9000:9000"
networks:
- laravel
redis:
image: redis:5.0.0-alpine
restart: always
container_name: redis
ports:
- "6379:6379"
networks:
- laravel
composer:
image: composer:latest
container_name: composer
volumes:
- ./src:/var/www/html
tty: true
working_dir: /var/www/html
networks:
- laravel
then i run
docker-compose up -d
and then
docker-compose ps
to see my container and i always get the composer contaier down with code 0. that's the screenshot
:
can someone explain me why i can't put this container up. Thanks a lot
composer isn't a program that stays alive. It's a program that does specific some work and then exits.
There's not much purpose in keeping it "up", since it's not going to do anything like the other processes do (nginx intercepts web traffic and writes response, mysql accepts database connections and reads/writes from a database, php serves web content, redis can be connected to as a cache).
I followed multiple guides and tutorials.
This is my docker-compose file.
It gives the following error,
services.mysql.environment.volumes contains ["mysql_data:/var/lib/mysql"], which is an invalid type, it should be a string, number, or a null
And it creates a volume with the name _volumename?
I just don't seem to get the mistake i made.
version : '3'
services:
mysql:
container_name: auth_db
restart: always
image: mysql:latest
environment:
MYSQL_ROOT_PASSWORD: supersecret
MYSQL_DATABASE: name
MYSQL_USER: user
MYSQL_PASS: supersecret2
volumes:
- mysql_data:/var/lib/mysql
ports:
- 3306:3306
auth-service:
build: ./authservice
volumes:
- ./authservice:/usr/src/app
ports:
- 5000:5000
volumes:
mysql_data:
Some more information.
If i change the volume line to
volumes: "- mysql_data:/var/lib/mysql"
The docker-compose file will compile but
docker volume ls gives this output
local 4fa81a11596c2b67c2bb799d54afc6009ebcd82fcd10acae53a5aeefd005fd36
local 8636df909155569e8ebf0649f4c192616d0b6778d5eb7932b1f9542db55a07d8
local 832739c89f3b33ad0a1974ad7dc2ee9342373f904af3b2be5934331bae50b5e6
local e5bb4a869f54ce3200d5a1fe129bc1f8ee46515cf03d9dd2ff327430d792117b
local e35a38127fcb07702a58133883a021aa56c4aad6c439d254f32a119ad380d808
local hell_mysql_data
My current dir where the docker-compose file is located is HELL that why i think it got the prefix from
Your issue is regarding indentation, volumes and ports must be top level first inside your service definition, as follows:
version : '3'
services:
mysql:
container_name: auth_db
restart: always
image: mysql:latest
environment:
MYSQL_ROOT_PASSWORD: supersecret
MYSQL_DATABASE: name
MYSQL_USER: user
MYSQL_PASS: supersecret2
volumes:
- mysql_data:/var/lib/mysql
ports:
- 3306:3306
auth-service:
build: ./authservice
volumes:
- ./authservice:/usr/src/app
ports:
- 5000:5000
volumes:
mysql_data:
I have two project using docker, in first project is laravel, and second is wordpress. In laravel I want to connect both database (to convert laravel database to wordpress database).
but I don't know how to connect it:
here is two docker-compose.yml file:
in laravel:
version: '2'
services:
# The Application
app:
build:
context: ./
dockerfile: app.dockerfile
working_dir: /var/www
volumes:
- ./:/var/www
environment:
- "DB_PORT=3306"
- "DB_HOST=database"
# The Web Server
web:
build:
context: ./
dockerfile: web.dockerfile
working_dir: /var/www
volumes_from:
- app
ports:
- 8081:80
# The Database
database:
image: mysql:5.6
volumes:
- dbdata:/var/lib/mysql
environment:
- "MYSQL_DATABASE=homestead"
- "MYSQL_USER=homestead"
- "MYSQL_PASSWORD=secret"
- "MYSQL_ROOT_PASSWORD=secret"
ports:
- "33061:3306"
volumes:
dbdata:
and my docker-compose.yml file in wordpress:
version: '2'
services:
db:
image: mysql:5.7
volumes:
- db_data:/var/lib/mysql
restart: always
environment:
MYSQL_ROOT_PASSWORD: 123456
MYSQL_DATABASE: wpshop
MYSQL_USER: root
MYSQL_PASSWORD: 123456
wordpress:
depends_on:
- db
image: wordpress:latest
volumes:
- ./:/var/www/html
ports:
- "8080:80"
restart: always
environment:
WORDPRESS_DB_HOST: db:3306
WORDPRESS_DB_USER: root
WORDPRESS_DB_PASSWORD: 123456
volumes:
db_data:
I cd to each project and run docker-compose up -d
Please help me!
Create an external network and use that network as default network for all your containers. This way you'll be able to reach all container by its name.
Take a look to Docker container networking: https://docs.docker.com/engine/userguide/networking/