I am new to docker
Here is my configuration
Folder Structure
Test :
- docker-compose.yml
- Dockerfile
- www
- index.html
Docker YML
version: "3"
services:
www:
build: .
ports:
- "8001:80"
volumes:
- ./www:/var/www/html/
links:
- db
networks:
- default
db:
image: mysql:8.0.16
command: ['--character-set-server=utf8mb4', '--collation-server=utf8mb4_unicode_ci','--default-authentication-plugin=mysql_native_password']
ports:
- "3306:3306"
environment:
MYSQL_DATABASE: myDb
MYSQL_USER: user
MYSQL_PASSWORD: test
MYSQL_ROOT_PASSWORD: test
volumes:
- ./dump:/docker-entrypoint-initdb.d
- persistent:/var/lib/mysql
networks:
- default
phpmyadmin:
image: phpmyadmin/phpmyadmin:4.8
links:
- db:db
ports:
- 8000:80
environment:
MYSQL_USER: user
MYSQL_PASSWORD: test
MYSQL_ROOT_PASSWORD: test
volumes:
persistent:
Dockerfile
FROM php:7.2.6-apache
RUN docker-php-ext-install mysqli pdo pdo_mysql gd curl
RUN a2enmod rewrite
RUN chmod -R 775 /var/www/html
phpmyadmin dashboard working correctly, But when i enter the web url it shows 403 forbidden error
When it check the log it shows an error like this :
[Mon Sep 02 12:00:44.290707 2019] [autoindex:error] [pid 18] [client 192.168.99.1:52312] AH01276: Cannot serve directory /var/www/html/: No matching DirectoryIndex (index.php,index.html) found, and server-generated directory index forbidden by Options directive
192.168.99.1 - - [02/Sep/2019:12:00:44 +0000] "GET / HTTP/1.1" 403 508 "-" "Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/73.0.3683.103 Safari/537.36"
and my "/var/www/html" directory was empty. How can i fix it ?
Update
I created a file index.php using bash it worked, but i can't locate index.php file on my file system
Please help
If you need any additional info feel free to ask :).
Thanks
Finally i figured the issue, i am using docker toolbox so it only mount C:\Users directory but my project folder is on d drive. so i have to mount my D:\projects directory to vm shared folder. i followed the below steps
In Virtual Box under 'Settings' -> 'Shared Folders' added 'projects'
and pointed it to the location I want to mount. In my case this is
'D:\projects' (Auto-mount and Make Permanent enabled)
Start Docker Quickstart Terminal
Type 'docker-machine ssh default' (the VirtualBox VM that Docker
uses is called 'default')
Go to the root of the VM filesystem, command 'cd /'
Switch to the user root by typing 'sudo su'
Create the directory you want to use as a mount point. Which in my
case is the same as the name of the shared folder in VirtualBox:
'mkdir projects'
Mount the VirtualBox shared folder by typing 'mount -t vboxsf -o
uid=1000,gid=50 projects /projects' (the first 'projects' is the
VirtualBox shared folder name, the second '/projects' is the
directory I just created and want to use as the mount point).
Now I can add a volume to my Docker file like this: '-
/projects/test/www/build/:/var/www/html/' (left side is the
/projects mount in my VM, the right side is the directory to mount
in my docker container)
Run the command 'docker-compose up' to start using the mount (to be
clear: run this command via the Docker Quickstart Terminal outside
of your SSH session on your local file system where your
docker-compose.yml file is located).
And i change the docker-compose.yml like this :
version: "3"
services:
www:
build:
context: .
dockerfile: Dockerfile
ports:
- "8001:80"
volumes:
- /projects/test/www:/var/www/html/
links:
- db
networks:
- default
db:
image: mysql:8.0.16
command: ['--character-set-server=utf8mb4', '--collation-server=utf8mb4_unicode_ci','--default-authentication-plugin=mysql_native_password']
ports:
- "3306:3306"
environment:
MYSQL_DATABASE: myDb
MYSQL_USER: user
MYSQL_PASSWORD: test
MYSQL_ROOT_PASSWORD: test
volumes:
- ./dump:/docker-entrypoint-initdb.d
- persistent:/var/lib/mysql
networks:
- default
phpmyadmin:
image: phpmyadmin/phpmyadmin:4.8
links:
- db:db
ports:
- 8000:80
environment:
MYSQL_USER: user
MYSQL_PASSWORD: test
MYSQL_ROOT_PASSWORD: test
volumes:
persistent:
i also updated the oracle vm.
I found this solution from here : https://github.com/moby/moby/issues/22430#issuecomment-215974613
Thanks bro :)
You need to modify your Dockerfile,
FROM php:7.2.6-apache
RUN docker-php-ext-install pdo_mysql
RUN a2enmod rewrite
COPY www/ /var/www/html
RUN chmod -R 775 /var/www/html
This will copy your www dir to /var/www/html dir inside container, let your web service run.
Related
I'm installed docker in windows server 2019 with DockerProvider
I'm using this code
Install-Module DockerProvider
Install-Package Docker -ProviderName DockerProvider -RequiredVersion preview
[Environment]::SetEnvironmentVariable("LCOW_SUPPORTED", "1", "Machine")
after that I install Docker-Compose with this code
[Net.ServicePointManager]::SecurityProtocol = [Net.SecurityProtocolType]::Tls12
Invoke-WebRequest "https://github.com/docker/compose/releases/download/1.24.0/docker-compose-Windows-x86_64.exe" -UseBasicParsing -OutFile $Env:ProgramFiles\Docker\docker-compose.exe
after that I use a docker compose file
version: "3.5"
services:
rabbitmq:
# restart: always
image: rabbitmq:3-management
container_name: rabbitmq
ports:
- 5672:5672
- 15672:15672
networks:
- myname
# network_mode: host
volumes:
- rabbitmq:/var/lib/rabbitmq
networks:
myname:
name: myname-network
volumes:
rabbitmq:
driver: local
everything is Ok up to here
but after i call http://localhost:15672/ url in my browser
rabbitmq crashes and I see this error in docker logs <container-id>
Cookie file /var/lib/rabbitmq/.erlang.cookie must be accessible by owner only
this .yml file is working correctly in docker for windows
but after running the file in windows server, I see this error
Solution is to map a different volume where the cookie file will be created;
https://github.com/docker-library/rabbitmq/issues/171#issuecomment-316302131
So for your example, not;
- rabbitmq:/var/lib/rabbitmq
but;
- rabbitmq:/var/lib/rabbitmq/mnesia
You also have the option to overwrite the command of the docker image to fix the issue it is complaining about. Assuming that your cookie file is /var/lib/rabbitmq/.erlang.cookie, replace the original docker image command, which is probably:
["rabbitmq-server"]
with:
["bash", "-c", "chmod 400 /var/lib/rabbitmq/.erlang.cookie; rabbitmq-server"]
In your docker-compose file it will look like this:
...
image: rabbitmq:3-management
...
ports:
- "5672:5672"
- "15672:15672"
volumes:
- ...
command: ["bash", "-c", "chmod 400 /var/lib/rabbitmq/.erlang.cookie; rabbitmq-server"]
Of course, you introduce here some workaround/technical debt that you assume rabbitmq-server will stay like that in the future.
I'm a little bit confused, I have a docker-compose file where I am trying to install apache and mariadb...
web:
image: php:5.6-apache
volumes:
- ./:/var/www/html/
environment:
- ALLOW_OVERRIDE=true
ports:
- "80:80"
links:
- db
db:
image: mariadb
restart: always
volumes:
- ./docker/db:/var/lib/mysql
environment:
MYSQL_ROOT_PASSWORD: root
MYSQL_USER: admin
MYSQL_PASSWORD: test
MYSQL_DATABASE: database
ports:
- "8889:3306"
Everything works fine until I try and do some URL rewriting in Apache and I get this...
web_1 | [Thu Apr 12 16:55:31.646473 2018] [core:alert] [pid 18] [client 172.17.0.1:34330] /var/www/html/applications/.htaccess: Invalid command 'RewriteEngine', perhaps misspelled or defined by a module not included in the server configuration
So I follow some online instructions to add a Dockerfile with...
FROM php:5.6-apache
MAINTAINER Raphael Mäder <ra#mader.com>
RUN a2enmod rewrite
ADD . /var/www/html
But it doesn't fix the problem. In fact even when I add an error into the file like this...
FROM php:5.6-apache
bleurrrrgggghhh
MAINTAINER Raphael Mäder <ra#mader.com>
RUN a2enmod rewrite
ADD . /var/www/html
And then call docker-compose everything boots up fine. So I know that the docker file can't be getting called. Even when I remove the image with docker-compose rm and restart it still nothing.
Am I getting confused about how I can run get the Dockerfile command working?
Once the image is built, it won't be built again, unless you explicitly want it to be rebuilt. With docker-compose, you pass the --build to force the image to be rebuilt.
docker-compose up --build web
I'm setting up a wordpress stack and having cross file permissions.
When using docker-compose up permissions seem not to be a problem but when using local docker swarm and using docker stack deploy, nginx gives me a 403 for file permission errors. When inspecting both the nginx:alpine container and the wordpress:php7.1-fpm-alpine container, i do indeed see that the containers each have different permission, on the nginx side it marks the files inside var/www/html as owned by user and group id 82 while on the php7.1 they are owned by www-data.
How can I make sure permission is correct across containers? The files are being bind mounted from the host.
```
version: '3'
services:
nginx:
depends_on:
- wordpress
image: private/nginx
build:
context: ./stack/nginx
volumes:
- "wordpress:/var/www/html"
ports:
- 80:80
wordpress:
depends_on:
- mysql
image: private/wordpress
build:
context: ./stack/wordpress
volumes:
- "wordpress:/var/www/html"
environment:
WORDPRESS_DB_USER: wordpress
WORDPRESS_DB_PASSWORD: password
mysql:
image: mariadb
volumes:
- "mysql:/var/lib/mysql"
environment:
MYSQL_ROOT_PASSWORD: password
MYSQL_DATABASE: wordpress
MYSQL_USER: wordpress
MYSQL_PASSWORD: password
volumes:
wordpress:
driver: local
driver_opts:
type: none
o: bind
device: "${PWD}/wordpress"
mysql:
```
For anyone else who comes across this question and has no solution,
this is how I approached the situation.
I added the following to my dockerfile, it creates a new www-datagroup AND user with the same id as the id that is used for the www-data user 82 & group 82 in the php-fpm image.
RUN set -x ; \
addgroup -g 82 -S www-data ; \
adduser -u 82 -D -S -G www-data www-data && exit 0 ; exit 1
To my docker file for nginx.
and in my nginx.conf i set the nginx worker user to the newly created ww-data user.
user www-data;
I'm trying to setup a Drupal site template however I have an issue, this is my current docker-compose:
version: '2'
services:
database:
image: mysql
container_name: database
command: mysqld --user=root --verbose
ports:
- "3306:3306"
environment:
MYSQL_DATABASE: "db"
MYSQL_USER: "user"
MYSQL_PASSWORD: "pass"
MYSQL_ROOT_PASSWORD: "root"
MYSQL_ALLOW_EMPTY_PASSWORD: "yes"
restart: always
site:
image: drupal
container_name: site
ports:
- "555:80"
volumes:
- ./drupal:/var/www/html
links:
- database:database
working_dir: /app
restart: always
volumes:
db:
Now if I do that the site doesn't work, no files are in the /var/www/html directory and the site 404's on everything. However if I remove the volume in the site container, it works perfectly and I can start setting it up as if it was a regular site.
What am I missing?
When you don't map a volume in the site service, that means Drupal is using whatever's already in /var/www/html from the drupal image. When you map the volume, you're overwriting /var/www/html with whatever's in ./drupal on the host machine. The results you're seeing imply there may be something wrong with the contents of ./drupal. To start with, I would run the service without mapping a volume and then copy the exact contents of /var/www/html into your local folder:
docker cp compose_site_1:/var/www/html/ ./drupal
Then try running the service again, this time with the volume mapped and see if that works. If it works, that tells you the problem was with the contents of ./drupal.
I'm pretty new to Docker but am trying to use it to clean up some of my projects. One such project is a fairly simple PHP/MySQL application. I've "docker-ized" the app by adding a docker-compose.yml with db and php services. Here's my docker-compose.yml:
version: '2'
services:
php:
build: .
ports:
- "80:80"
- "443:443"
volumes:
- ./public_html:/var/www/html
links:
- db
db:
image: mysql:5.5
ports:
- "3306:3306"
environment:
MYSQL_USER: root
MYSQL_PASSWORD:
MYSQL_ROOT_PASSWORD:
MYSQL_ALLOW_EMPTY_PASSWORD: 'yes'
volumes:
- /c/dockerdata:/var/lib/mysql
This works correctly however I have to change all my PHP scripts to use "db" instead of "localhost" when connecting to the mysql database. I'm adding the docker stuff just as a way to clean up development so I'm trying to avoid changing the PHP code itself. Is there a way I can configure this so I'm able to use localhost or 127.0.0.1 to connect?
Docker doesn't allow you to modify /etc/hosts on containers Known issue
You can edit /etc/hosts with entrypoint option
Create entrypoint.sh script
#!/bin/bash
cp /etc/hosts /tmp/hosts
sed -e '/localhost/ s/^#*/#/' -i /tmp/hosts
cp /tmp/hosts /etc/hosts
# add your command here to run php application
Add execute permissions to entrypoint.sh
chmod +x entrypoint.sh
Add below two lines to Dockerfile
ADD entrypoint.sh /entrypoint.sh
ENTRYPOINT /entrypoint.sh
Now do the step 2) from my previous answer.
You can achieve this using below two steps
1) Add below CMD to your Dockerfile
CMD sed -e '/localhost/ s/^#*/#/' -i /etc/hosts
2) Replace 'db' with 'localhost' in docker-compose.yml
links:
- db
db:
image: mysql:5.5
as
links:
- localhost
localhost:
image: mysql:5.5