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
Related
I've install MySQL and PhpMyAdmin on docker
MySQL volume mount works perfectly fine,
But I also want container's /var/www/html/libraries, /var/www/html/themes folders to be saved/persisted to my host.
So that If I change any file and it stays like that..
This is my docker-compose.yml
version: '3.5'
services:
mysql:
container_name: mysql
image: mysql
restart: always
volumes:
- ./var/lib/mysql:/var/lib/mysql
environment:
MYSQL_ROOT_PASSWORD: root
phpmyadmin:
container_name: phpmyadmin
image: phpmyadmin/phpmyadmin:latest
restart: always
volumes:
- ./phpmyadmin/libraries:/var/www/html/libraries # Here's the problem
- ./phpmyadmin/themes:/var/www/html/themes # Here's the problem
environment:
PMA_HOST: mysql
The current problem is,
it does create the folders /phpmyadmin/libraries, /phpmyadmin/themes
But inside they're empty and the container's directories (/var/www/html/libraries, /var/www/html/themes) also becomes empty.
I'm very new to Docker, and currently I've no clue :(
Many Thanks in advance.
Your problem is that /var/www/html is populated at build time and volumes are mounted at run time which causes /var/www/html to be overwritten by what you have locally (i.e. nothing).
You need to extend the Dockerfile for PHPMyAdmin to delay populating those directories until after the volumes have been mounted. You'll need something like this setup:
Modify docker-compose.yml to the following:
...
phpmyadmin:
container_name: phpmyadmin
build:
# Use the Dockerfile located at ./build/phpmyadmin/Dockerfile to build this image
context: ./build/phpmyadmin
dockerfile: Dockerfile
restart: always
volumes:
- ./phpmyadmin/libraries:/var/www/html/libraries
- ./phpmyadmin/themes:/var/www/html/themes
environment:
PMA_HOST: mysql
Create a file at ./build/phpmyadmin/Dockerfile with this content:
FROM phpmyadmin/phpmyadmin:latest
# Move the directories you want into a temporary directory
RUN mv /var/www/html /tmp/
# Modify the start up of this image to use a custom script
COPY ./custom-entrypoint.sh /custom-entrypoint.sh
RUN chmod +x /custom-entrypoint.sh
ENTRYPOINT ["/custom-entrypoint.sh"]
CMD ["apache2-foreground"]
Create a custom entrypoint at ./build/phpmyadmin/custom-entrypoint.sh with this content:
#!/bin/sh
# Copy over the saved files
cp -r /tmp/html /var/www
# Kick off the original entrypoint
exec /docker-entrypoint.sh "$#"
Then you can build and start everything with docker-compose up --build.
Note: this will probably cause issues for you if you're trying to version control these directories - you'll probably need to modify custom-entrypoint.sh.
Im few days in one project where I have a task of using Docker. After following few tutorials I find the easy way of deploying my LAMP server using docker-compose that looks like this:
version: '3.7'
services:
php-httpd:
image: php:7.3-apache
ports:
- 80:80
volumes:
- "./DocumentRoot:/var/www/html"
mariadb:
image: mariadb:10.5.2
volumes:
- mariadb-volume:/var/lib/mysql
environment:
TZ: "Europe/Rome"
MYSQL_ALLOW_EMPTY_PASSWORD: "no"
MYSQL_ROOT_PASSWORD: "rootpwd"
MYSQL_USER: 'testuser'
MYSQL_PASSWORD: 'testpassword'
MYSQL_DATABASE: 'testdb'
phpmyadmin:
image: phpmyadmin/phpmyadmin
links:
- 'mariadb:db'
ports:
- 8081:80
volumes:
mariadb-volume:
Now after my app is in middle of development i find a problem that I need to edit the .htaccess to turn on mod_rewrite and add some rules for REST API.
All solutions that I find are mentioning that I should add RUN command in dockerfile similar to this:
FROM httpd:alpine
# Copy .htaccess into DocumentRoot
COPY ./.htaccess /var/www/html/
RUN sed -i '/LoadModule rewrite_module/s/^#//g' /usr/local/apache2/conf/httpd.conf
But I dont have that file, and offical documentation is of no help for me.
All I do is sudo docker-compose up -d to run my images. So question is:
In what stage, how and where should I add this file to make it work.
I know is possible cose I find this statement in one tutorial:
Next time around, we'll create a more complicated docker-compose.yml
file, one that works in conjunction with a Dockerfile.
But there was no followup on this.
I would appreciate any guidance on this.
Also I know I can access PHP image with: docker exec -it linuxconfig_php-httpd_1 bash.
Maybe I can do something with that?
You have two options:
Docker is a layered file system, You can use one image and make modifications to it to create another image, which you can then push to your private Docker Registry or public dockerhub. To, create a custom image with your .htaccess changes, you will create a file named "Dockerfile". You will then place the Dockerfile in the same directory where your modified .htaccess
Dockerfile content
FROM php:7.3-apache
RUN sed -i '/LoadModule rewrite_module/s/^#//g' /usr/local/apache2/conf/httpd.conf
Create Image:
docker build -t custom-php:7.3-apache .
This will create a new image name (custom-php:7.3-apache). You can then use this new image in your docker-compose.yml file and when deployed, the container will have the updated .htaccess
You may mount the .htaccess to the desired path by using volumes option as shown below
.
php-httpd:
image: php:7.3-apache
ports:
- 80:80
volumes:
- "./DocumentRoot:/var/www/html"
- "./.htaccess:/var/www/html/.htaccess"
I prefer #2 as you can edit .htaccess rules without rebuilding the image.
I've been using: docker build -t devstack .
docker run --rm -p 443:443 -it -v ~/code:/code devstack
That has been working fine for me so far. I've been able to access the site as expected through my browser. I set my hosts file to point devstack.com to 127.0.0.1 and the site loads nicely. Now I'm trying to use docker-compose so I can use some of the functionality there to more easily connect with AWS.
services:
web:
build:
context: .
network_mode: "bridge"
ports:
- "443"
- "80"
volumes:
- ~/code:/code
image: devstack:latest
So I run docker-compose build which gives me the familiar build stuff from Dockerfile.
Then I run docker-compose run web which puts me into the VM where I start apache (doing it manually at the moment), hit top to verify it’s running, then tail the log files. But when I attempt to hit the site in my browser, I get: devstack.com refused to connect. and no logs in the apache log files, so it's not even getting to apache. So something about the ports isn't opening up to me. Any idea what I need to change to make this work?
Edit: Updated file. Still same problem:
version: "3"
services:
web:
build:
context: .
# Same issue with both of these:
# network_mode: "bridge"
# network_mode: "host"
ports:
- "443:443"
- "80:80"
volumes:
- ~/code:/code
tty: true
This is what I did to get it working. I used the example project docker-compose showed in their documentation, which runs a test app on port 5000. That worked, so I knew it could be done.
I updated my docker-compose.yml to be very similar to the one in the test project. So it looks like this now:
version: "3"
services:
web:
build: .
ports:
- "443:443"
- "80:80"
volumes:
- ~/code:/code
Then I created an entry.sh file which will start apache, and added this to my Dockerfile:
# copy the entry file which will start apache
COPY entry.sh entry.sh
RUN chmod +x entry.sh
# start apache
CMD ./entry.sh; tail -f /var/log/apache2/*.log
So now when I do docker-compose up, it will start apache and tail the apache log files. So I immediately see apache log files output to terminal. Then I'm able to access the site. Basically the problem was just with the VM exiting. This was the only way I could find to keep it from exiting without doing tty=true in the docker-compose, which while it kept it from exiting, wouldn't publish the ports.
I am running all of these operations on a remove server that is a
VM running Ubuntu 16.04.5 x64.
My Go project's Dockerfile looks like:
FROM golang:latest
ADD . $GOPATH/src/example.com/myapp
WORKDIR $GOPATH/src/example.com/myapp
RUN go build
#EXPOSE 80
#ENTRYPOINT $GOPATH/src/example.com/myapp/myapp
ENTRYPOINT ./myapp
#CMD ["./myapp"]
When I run the docker container using docker-compose up -d, the Go application exits and I see this in the docker logs:
myapp_1 | /bin/sh: 1: ./myapp: Exec format error docker_myapp_1
exited with code 2
If I locate the image using docker images and run the image like:
docker run -it 75d4a95ef5ec
I can see that my golang applications runs just fine:
viper environment is: development HTTP server listening on address:
":3005"
When I googled for this error some people suggested compiling with some special flags but I am running this container on the same Ubuntu host so I am really confused why this isn't working using docker.
My docker-compose.yml looks like:
version: "3"
services:
openresty:
build: ./openresty
ports:
- "80:80"
- "443:443"
depends_on:
- myapp
env_file:
- '.env'
restart: always
myapp:
build: ../myapp
volumes:
- /home/deploy/apps/myapp:/go/src/example.com/myapp
ports:
- "3005:3005"
depends_on:
- db
- redis
- memcached
env_file:
- '.env'
redis:
image: redis:alpine
ports:
- "6379:6379"
volumes:
- "/home/deploy/v/redis:/data"
restart: always
memcached:
image: memcached
ports:
- "11211:11211"
restart: always
db:
image: postgres:9.4
volumes:
- "/home/deploy/v/pgdata:/var/lib/postgresql/data"
restart: always
Your docker-compose.yml file says:
volumes:
- /home/deploy/apps/myapp:/go/src/example.com/myapp
which means your host system's source directory is mounted over, and hides, everything that the Dockerfile builds. ./myapp is the host's copy of the myapp executable and if something is different (maybe you have a MacOS or Windows host) that will cause this error.
This is a popular setup for interpreted languages where developers want to run their application without running a normal test-build-deploy sequence, but it doesn't really make sense for a compiled language like Go where you don't have a choice. I'd delete this block entirely.
The Go container stops running because of this:
WORKDIR $GOPATH/src/example.com/myapp
RUN go build
#EXPOSE 80
#ENTRYPOINT $GOPATH/src/example.com/myapp/myapp
ENTRYPOINT ./myapp
You are switching directories to $GOPATH/src/example.com/myapp where you build your app, however, your entry point is pointing to the wrong location.
To solve this, you either copy the app into the root directory and keep the same ENTRYPOINT command or you copy the application to a different location and pass the full path such as:
ENTRYPOINT /my/go/app/location
My docker-compose.yml is:
wordpress:
image: wordpress
links:
- wordpress_db:mysql
ports:
- 8007:8007
volumes:
- ~/wpme/wptest/wp_html:/var/www/html
wordpress_db:
image: mysql
ports:
- 3316:3316
environment:
MYSQL_USERNAME: root
MYSQL_ROOT_PASSWORD: root
The command that i run on terminal is:
sudo docker-compose up
The error that I get:
Error, Container command 'docker-entrypoint.sh' not found or does not exist.
What's happening? (I'm on ubuntu 14.04)
In my case, the docker-entrypoint.sh was using Windows instead of Unix line endings.
Converting the file to \n fixed the issue.
It means one of your containers in their dockerfile have a command either on entrypoint or cmd that calls docker-entrypoint.sh and doesnt finds it.