Volume edited by systemd-coredump docker - docker

I'm trying to make a Symfony project running in docker container.
So, there is my docker-compose.yml :
version: '3.7'
services:
mariadb:
image: ${MARIADB_VERSION}
restart: on-failure
environment:
MYSQL_ROOT_PASSWORD: ${MYSQL_ROOT_PASSWORD}
MYSQL_DATABASE: ${MYSQL_DATABASE}
MYSQL_USER: ${MYSQL_USER}
MYSQL_PASSWORD: ${MYSQL_PASSWORD}
ports:
- ${PORTS_MARIADB}
volumes:
- './db/:/var/lib/mysql'
php:
build:
context: .
dockerfile: docker/php/Dockerfile
volumes:
- './app/:/usr/src/app'
restart: on-failure
user: 1000:1000
nginx:
image: ${NGINX_VERSION}
restart: on-failure
volumes:
- './app/public/:/usr/src/app'
- './docker/nginx/default.conf:/etc/nginx/conf.d/default.conf:ro'
ports:
- ${PORTS_NGINX}
depends_on:
- php
I start my container like this (with non-root user):
docker-compose build
docker-compose up -d
So, at this point, all is ok but, If I want to re-build my docker container:
docker-compose down
docker-compose build
The volume ./db (of mariadb) have his permissions set to systemd-coredump:findl users (findl is mine)
So, I have this error when I try to build the container:
Why the permissions to the volume /db are set to another user... ?
Regards

As a result of this Github issue reply, I was able to fix my issues and move on. Basically, take the temporary portion of your volume and add it to .dockerignore. The commenter does a much better explanation of why it works than I would ever be able to muster here, but if this gets you (or anyone else who runs into this issue) farther along, then so be it.

Related

How to solve MySQL database data disappear in Docker Swarm

When I use docker swarm with MySQL I met with problem (If docker container rerun mysql data will disappear)
I spend a lot of time to search how to fix this problem, use volume store data and use glusterFs across host share volume but experiencing database data inconsistency.
Is my method right ? or can someone tell we how to fix this problem?
At last , This is my example yaml file :
version: '3.8'
services:
www:
image: httpd:latest
ports:
- "8001:80"
volumes:
- /usr/papertest/src:/var/www/html/
db:
image: mariadb:latest
restart: always
volumes:
- /usr/test/src:/docker-entrypoint-initdb.d
- /etc/timezone:/etc/timezone:ro
- /usr/test/backup:/var/lib/mysql #/usr/test/backup is glusterfs mount place
environment:
MYSQL_ROOT_PASSWORD: MySQL_PASSWORD
MYSQL_DATABASE: MYSQL_DATABASE
#MYSQL_USER: MYSQL_USER
# MYSQL_PASSWORD: MYSQL_PASSWD
phpmyadmin:
image: phpmyadmin
#restart: always
ports:
- 4567:80
environment:
- PMA_ARBITRARY=1

Docker image very slow

I am trying to build a Prestashop image using Docker Compose, I use this docker-compose.yml file
version: "3.7"
services:
app:
build: .
image: prestashop/prestashop:1.7
ports:
- 8080:80
working_dir: /var/www/html
volumes:
- ./:/var/www/html
environment:
PS_DOMAIN: localhost
DB_SERVER: mysql
MYSQL_USER: root
MYSQL_PASSWORD: mypass123
MYSQL_DB: prestashop
dns: 8.8.8.8
mysql:
image: mysql:5.7
environment:
MYSQL_ROOT_PASSWORD: mypass123
MYSQL_DATABASE: prestashop
phpmyadmin:
image: phpmyadmin/phpmyadmin
ports:
- 8081:80
environment:
MYSQL_ROOT_PASSWORD: mypass123
MYSQL_DATABASE: prestashop
PMA_HOST: mysql
But every time I start it, the server does not respond for several minutes (Firefox says "connection was reset"). And once I can eventually access to the webpage, it is very slow.
Is it something that I can solve by changing my docker-compose file ?
Thanks a lot !
You may use .dockerignore in your build.
This helps to avoid unnecessarily sending large or sensitive files and directories to the daemon .
https://docs.docker.com/engine/reference/builder/#dockerignore-file
also check this out for best practices https://docs.docker.com/develop/develop-images/dockerfile_best-practices/

Lost volume when run docker-compose

I had running container with wordpress and other container with MySQL and its volume (see config below). Then I've run docker-compose up -d --build and then I see wordpress installation page, that means empty database. Also I could kill some docker process before that, don't remember exactly which by command ```sudo kill -9 [process_id].
Where can I find solution to restore my volume with all the information this has?
services:
wordpress:
depends_on:
- db
image: wordpress:latest
volumes:
- ./uploads.ini:/usr/local/etc/php/conf.d/uploads.ini
- wordpress_files:/var/www/html
ports:
- "80:80"
restart: always
environment:
WORDPRESS_DB_HOST: db:3306
WORDPRESS_DB_USER: wordpress
WORDPRESS_DB_PASSWORD: my_wordpress_db_password
db:
image: mysql:5.7
volumes:
- db_data:/var/lib/mysql
restart: always
ports:
- "3306:3306"
environment:
MYSQL_ROOT_PASSWORD: my_db_root_password
MYSQL_DATABASE: wordpress
MYSQL_USER: wordpress
MYSQL_PASSWORD: my_wordpress_db_password
volumes:
wordpress_files:
db_data:
uploads.ini:
You should take a look at the output of "docker volume ls". If you were using the container only with the docker run command and now switched to compose, maybe you when you runned docker-compose up Docker created a new empty volume called db_db_data.

docker-compose not restarting correctly

i have the following docker-compose.yml
The restart of the mediawiki_db container is working.
The problem is, that the mediawiki container will not restart after reboot besides the fact that it also has the restart: always policy.
# MediaWiki with MariaDB
#
# Access via "http://localhost:8080"
# (or "http://$(docker-machine ip):8080" if using docker-machine)
version: '2'
services:
mediawiki_db:
image: mariadb
restart: always
container_name: mediawiki_db
volumes:
- ~/wiki/mysql:/var/lib/mysql
environment:
# #see https://phabricator.wikimedia.org/source/mediawiki/browse/master/includes/DefaultSettings.php
MYSQL_DATABASE: 'my_wiki'
MYSQL_USER: 'wikiuser'
MYSQL_PASSWORD: 'pw'
MYSQL_RANDOM_ROOT_PASSWORD: 'yes'
mediawiki:
image: mediawiki
restart: always
container_name: mediawiki
ports:
- 8080:80
volumes:
- ~/wiki/var/www/html/images:/var/www/html/images
# After initial setup, download LocalSettings.php to the same directory as
# this yaml and uncomment the following line and use compose to restart
# the mediawiki service
- ./LocalSettings.php:/var/www/html/LocalSettings.php
depends_on:
- mediawiki_db
What is it i am doing wrong?
As far as I can tell from the MediaWiki DockerFile, there is no CMD being run when you start up the container.
Someone correct me if I'm wrong, but I think the restart: always can only work if there is a command that docker-compose is monitoring. And therefore restart the container with.

Docker-Compose persistent data MySQL

I can't seem to get MySQL data to persist if I run $ docker-compose down with the following .yml
version: '2'
services:
# other services
data:
container_name: flask_data
image: mysql:latest
volumes:
- /var/lib/mysql
command: "true"
mysql:
container_name: flask_mysql
restart: always
image: mysql:latest
environment:
MYSQL_ROOT_PASSWORD: 'test_pass' # TODO: Change this
MYSQL_USER: 'test'
MYSQL_PASS: 'pass'
volumes_from:
- data
ports:
- "3306:3306"
My understanding is that in my data container using volumes: - /var/lib/mysql maps it to my local machines directory where mysql stores data to the container and because of this mapping the data should persist even if the containers are destroyed. And the mysql container is just a client interface into the db and can see the local directory because of volumes_from: - data
Attempted this answer and it did not work. Docker-Compose Persistent Data Trouble
EDIT
Changed my .yml as shown below and created a the dir ./data but now when I run docker-compose up --build the mysql container wont start throws error saying
data:
container_name: flask_data
image: mysql:latest
volumes:
- ./data:/var/lib/mysql
command: "true"
mysql:
container_name: flask_mysql
restart: always
image: mysql:latest
environment:
MYSQL_ROOT_PASSWORD: 'test_pass' # TODO: Change this
MYSQL_USER: 'test'
MYSQL_PASS: 'pass'
volumes_from:
- data
ports:
- "3306:3306"
flask_mysql | mysqld: Can't create/write to file '/var/lib/mysql/is_writable' (Errcode: 13 - Permission denied)
flask_mysql | 2016-08-26T22:29:21.182144Z 0 [Warning] TIMESTAMP with implicit DEFAULT value is deprecated. Please use --explicit_defaults_for_timestamp server option (see documentation for more details).
flask_mysql | 2016-08-26T22:29:21.185392Z 0 [ERROR] --initialize specified but the data directory exists and is not writable. Aborting.
The data container is a superfluous workaround. Data-volumes would do the trick for you. Alter your docker-compose.yml to:
version: '2'
services:
mysql:
container_name: flask_mysql
restart: always
image: mysql:latest
environment:
MYSQL_ROOT_PASSWORD: 'test_pass' # TODO: Change this
MYSQL_USER: 'test'
MYSQL_PASS: 'pass'
volumes:
- my-datavolume:/var/lib/mysql
volumes:
my-datavolume:
Docker will create the volume for you in the /var/lib/docker/volumes folder. This volume persist as long as you are not typing docker-compose down -v
There are 3 ways:
First way
You need specify the directory to store mysql data on your host machine. You can then remove the data container. Your mysql data will be saved on you local filesystem.
Mysql container definition must look like this:
mysql:
container_name: flask_mysql
restart: always
image: mysql:latest
environment:
MYSQL_ROOT_PASSWORD: 'test_pass' # TODO: Change this
MYSQL_USER: 'test'
MYSQL_PASS: 'pass'
volumes:
- /opt/mysql_data:/var/lib/mysql
ports:
- "3306:3306"
Second way
Would be to commit the data container before typing docker-compose down:
docker commit my_data_container
docker-compose down
Third way
Also you can use docker-compose stop instead of docker-compose down (then you don't need to commit the container)
first, you need to delete all old mysql data using
docker-compose down -v
after that add two lines in your docker-compose.yml
volumes:
- mysql-data:/var/lib/mysql
and
volumes:
mysql-data:
your final docker-compose.yml will looks like
version: '3.1'
services:
php:
build:
context: .
dockerfile: Dockerfile
ports:
- 80:80
volumes:
- ./src:/var/www/html/
db:
image: mysql
command: --default-authentication-plugin=mysql_native_password
restart: always
environment:
MYSQL_ROOT_PASSWORD: example
volumes:
- mysql-data:/var/lib/mysql
adminer:
image: adminer
restart: always
ports:
- 8080:8080
volumes:
mysql-data:
after that use this command
docker-compose up -d
now your data will persistent and will not be deleted even after using this command
docker-compose down
extra:- but if you want to delete all data then you will use
docker-compose down -v
You have to create a separate volume for mysql data.
So it will look like this:
volumes_from:
- data
volumes:
- ./mysql-data:/var/lib/mysql
And no, /var/lib/mysql is a path inside your mysql container and has nothing to do with a path on your host machine. Your host machine may even have no mysql at all. So the goal is to persist an internal folder from a mysql container.
Adding on to the answer from #Ohmen, you could also add an external flag to create the data volume outside of docker compose. This way docker compose would not attempt to create it. Also you wouldn't have to worry about losing the data inside the data-volume in the event of $ docker-compose down -v.
The below example is from the official page.
version: "3.8"
services:
db:
image: postgres
volumes:
- data:/var/lib/postgresql/data
volumes:
data:
external: true
Actually this is the path and you should mention a valid path for this to work. If your data directory is in current directory then instead of my-data you should mention ./my-data, otherwise it will give you that error in mysql and mariadb also.
volumes:
./my-data:/var/lib/mysql
Feasible bind mount solution:
mariadb:
image: mariadb:latest
restart: unless-stopped
environment:
- MARIADB_ROOT_PASSWORD=${MARIADB_ROOT_PASSWORD}
volumes:
- type: bind
source: /host/dir
target: /var/lib/mysql

Resources