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/
Related
I am trying to setup a WordPress project on my machine using Docker. This is my docker-compose.yml file code:
version: "3"
services:
# Database
db:
image: mysql:5.7
volumes:
- db_data:/var/lib/mysql
restart: always
environment:
MYSQL_ROOT_PASSWORD: password
MYSQL_DATABASE: wordpress
MYSQL_USER: wordpress
MYSQL_PASSWORD: wordpress
networks:
- wp
# Web Server
wordpress:
ports:
- "4000:80"
depends_on:
- db
image: wordpress:latest
restart: always
volumes:
- "./html/:/var/www/html/"
environment:
WORDPRESS_DB_HOST: db:3306
WORDPRESS_DB_USER: wordpress
WORDPRESS_DB_PASSWORD: wordpress
WORDPRESS_DB_NAME: wordpress
networks:
- wp
networks:
wp:
volumes:
db_data:
This works fine but what it does is, that the files that are mounted inside ./html folder has user and group permission assigned as www-data:www-data. I am working on Ubuntu desktop OS. So every time I try to update any code inside ./html folder, I get permission denied message.
Is there any way I can fix this issue?
I have tried this command to add my user to www-data group but that didn't work aswell.
sudo usermod -aG www-data aslam
Try to match the user's id on the host machine to match that of www-data inside the container or vice-versa. May be read this for more info and howto.
To be clear for everyone else, adding user: 0:0 to the docker-compose.yml file solved this issue for me too.
There isn't a problem with file permissions when you mount the files on windows... but I feel like mounting to Windows isn't a good idea because the response time to the application is very slow that way.
Here's the full docker-compose.yml
Running this in your WSL of choice will prevent the permissions issues.
version: '3.3'
services:
wptoolkit:
# add user declaration to avoid windows permission issues when editing files and folders through your favorite editor
user: 0:0
# Ensure DB is up
depends_on:
- db
# We'll use the most recent Wordpress install
image: wordpress:latest
# Map files from container back to linux at this directory location
volumes:
- ./:/var/www/html
ports:
# We'll access our site on http://localhost:8999
- "80:80"
restart: always
environment:
# We'll provide some SQL credentials -- these match what's
# in our db section
- WORDPRESS_DB_HOST=db
- WORDPRESS_DB_USER=wordpress
- WORDPRESS_DB_PASSWORD=wordpress
- WORDPRESS_DB_NAME=wordpress
# This is our MySQL database server
db:
# We use a mariadb image which supports both amd64 & arm64 architecture
image: mariadb:10.6.4-focal
# If you really want to use MySQL, uncomment the following line
#image: mysql:8.0.27
command: '--default-authentication-plugin=mysql_native_password'
volumes:
- db_data:/var/lib/mysql
restart: always
environment:
- MYSQL_ROOT_PASSWORD=wordpress
- MYSQL_DATABASE=wordpress
- MYSQL_USER=wordpress
- MYSQL_PASSWORD=wordpress
expose:
- 3306
- 33060
phpmyadmin:
image: phpmyadmin/phpmyadmin
container_name: pma
links:
- db
environment:
PMA_HOST: db
PMA_PORT: 3306
PMA_ARBITRARY: 1
restart: always
ports:
- 8081:80
volumes:
db_data:
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 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.
New to Docker and I'm trying to set up as a development environment on a Drupal 7 project. I'm running into this error when I visit localhost:8080 after running docker-compose up:
Error
The website encountered an unexpected error. Please try again later.
Error messagePDOException: SQLSTATE[HY000] [2002] No such file or directory in lock_may_be_available() (line 167 of /var/www/html/includes/lock.inc).
It looks like it's having an issue connecting to my database. When I run docker ps -a I can see my 2 containers are up and running, so they seem to build just fine. My issue is just connecting my drupal container to the mysql container.
Here is my docker-compose.yml file:
version: '2'
services:
drupal:
image: drupal:7.53-apache
container_name: app
volumes:
- ./:/var/www/html
ports:
- '8080:80'
links:
- mysql
mysql:
image: mysql:5.6.35
container_name: app_db
environment:
MYSQL_ROOT_PASSWORD: root
MYSQL_USER: root
MYSQL_PASSWORD: root
MYSQL_DATABASE: testdb
Am I overlooking something else that would connect the two containers? Any and all help is greatly appreciated. Thanks!
try to map the correct ports and the php DATABASE_HOST. for me this works:
db:
image: dev/mysql
ports:
- "3306:3306"
environment:
MYSQL_DATABASE: testdb
MYSQL_USER: root
MYSQL_PASSWORD: root
php:
image: dev/alpine-nginx-php5.6
environment:
DATABASE_HOST: db
ports:
- "80:80"
- "443:443"
volumes:
- ./SRC:/var/www/
links:
- db
but i would suggest to store your database outside of the docker-container. if you have to rebuild or it has a fatal crash everything is deleted.