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.
Related
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/
I'm new to Docker and created myself a Container using a Compose File.
Now I came to a point where I wanted to use my development result in production.
Is there any way to backup the whole content so that I can use it in a production environment ?
The compose file that I used to spin up my Container:
version: '3.3'
services:
db:
image: mysql:5.7
volumes:
- db_data:/var/lib/mysql
restart: always
environment:
MYSQL_ROOT_PASSWORD: myRootPassword
MYSQL_DATABASE: wordpress_oxygen
MYSQL_USER: wordpress_oxygen
MYSQL_PASSWORD: myDBPassword
wordpress:
depends_on:
- db
image: wordpress:latest
ports:
- "8000:80"
restart: always
environment:
WORDPRESS_DB_HOST: db:3306
WORDPRESS_DB_USER: wordpress
WORDPRESS_DB_PASSWORD: wordpress
WORDPRESS_DB_NAME: wordpress
volumes:
db_data: {}
Docker compose is not for production. For production try docker swarm.
Also you should add volume for wordpress, see example
https://hub.docker.com/_/wordpress
How backup volumes please see https://docs.docker.com/storage/volumes/#backup-restore-or-migrate-data-volumes
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.
I'm new to the docker world and maybe I'm missing something.
I created the following docker-compose file
version: '3.3'
services:
db:
image: mysql:latest
restart: always
volumes:
- db_data:/var/lib/mysql
environment:
MYSQL_ROOT_PASSWORD: password
MYSQL_DATABASE: wordpress
MYSQL_USER: wordpress
MYSQL_PASSWORD: wordpress
networks:
- wpsite
phpmyadmin:
depends_on:
- db
image: phpmyadmin/phpmyadmin
ports:
- '8080:80'
environment:
PMA_HOST: db
MYSQL_ROOT_PASSWORD: password
networks:
- wpsite
wp:
depends_on:
- db
image: andreccosta/wordpress-xdebug
volumes:
- ./wp:/var/www/html
ports:
- 8000:80
restart: always
environment:
WORDPRESS_DB_HOST: db:3306
WORDPRESS_DB_USER: wordpress
WORDPRESS_DB_PASSWORD: wordpress
XDEBUG_CONFIG: remote_host=172.17.0.1
networks:
- wpsite
networks:
wpsite:
volumes:
db_data:
When i run it with docker-compose up everything goes well, but when I try to access localhost:8080 (path for phpmyadmin) and try to login i'm not able to connect to mysql.
If i try to enter the mysql container with
docker exec -t -i <conatiner_name> bash
and try to login to mysql i'm able to do it.
I used this same file on a different computer and everything works well.
I'm running docker on ubuntu.
UPDATE
I solved the issue by changing the version of the mysql image from latest to 5.7.27.
I've got a docker-compose.yml that looks like this:
version: '3'
services:
db:
image: mysql:5.7
volumes:
- db_data:/var/lib/mysql2
restart: always
ports:
- "3306:3306"
environment:
MYSQL_ROOT_PASSWORD: somewordpress
MYSQL_DATABASE: wptest
MYSQL_USER: wordpress
MYSQL_PASSWORD: wordpress
wordpress:
volumes:
- ./site/:/var/www/html/
- ~/playground/certs/:/etc/ssl/certs/
depends_on:
- db
image: wordpress:latest
ports:
- "80:80"
restart: always
environment:
WORDPRESS_DB_HOST: db:3306
WORDPRESS_DB_NAME: wptest
WORDPRESS_DB_USER: wordpress
WORDPRESS_DB_PASSWORD: wordpress
volumes:
db_data:
It works and my wordpress installation is fine - except for the fact that there is a self-signed cert in the mix. So when I try to update my wordpress installation or something, it fails (same with plugins).
If I get into the bash shell of the container and run update-ca-certificates it finds my keys and installs them and then I can run updates without issue.
My question is - can I automate that, so it automatically pulls in my certs and runs the command after the container is up while still allowing me to use docker-compose up ?
You can create a simple Dockerfile that pulls from the wordpress image and add a RUN command with whatever you want to do.
FROM wordpress:latest
RUN your-command-here
And then change you docker-compose to use this new image instead of the official wordpress one, probably something like:
(notice the build arguments)
wordpress:
volumes:
- ./site/:/var/www/html/
- ~/playground/certs/:/etc/ssl/certs/
depends_on:
- db
build:
context: .
dockerfile: ./Dockerfile
ports:
- "80:80"
restart: always
environment:
WORDPRESS_DB_HOST: db:3306
WORDPRESS_DB_NAME: wptest
WORDPRESS_DB_USER: wordpress
WORDPRESS_DB_PASSWORD: wordpress