I try to migrate most of my server apps to docker. I basically have a Apache2 running on my host and some PHP based WebApps as docker containers using FPM.
As my knowledge goes, only the *.php files are served through the docker container, those this configuration must be added to Apache2:
ProxyPassMatch "^/phpMyAdmin/(.*\.php)$" "fcgi://localhost:9000/var/www/html/$1"
So you can't pass any static files (CSS, JavaScript) to the fpm container. Therefore I usually mount a host directory to the container like so:
docker run -v /var/www/phpMyAdmin:/var/www/html -p 9000:9000 -d phpmyadmin:fpm-alpine
But as soon as I add the mount (-v), the containers "/var/www/html" directory is empty. I checked with:
docker exec -it phpmyadmin /bin/sh
It seems like the whole phpMyAdmin installation wasn't extracted or got deleted/overwritten. This approach did work for other containers (postfixadmin, roundcube), so I have no idea what is going on or what I'm doing wrong.
How am I supposed to serve the static files from the fpm docker container through my Apache2 host? I didn't find any example, only nginx as server or docker compose.
Best regards,
Billie
Related
I am running a nginx application using docker. My nginx application creates some files in the docker container. I can see those files in the directory. I tried those files from my flask application, but I cannot since I am running my flask application in another docker container.
Is there a way to read files from a docker container inside a flask application running in localhost/docker?
You can explore docker container's file system via;
docker exec -it [containerId] bash
also you can try docker cp.
I'm using docker toolbox in my Win 7 desktop, I'm creating a container from nginx using the following command:
docker container run -p 8082:80 -v //c/Users/TestDocker/:/usr/share/nginx/ -d --rm nginx
The content in the container reflects what it is in my host folder:
In the container:
But the actual page display is this:
Obviously the same locally:
Nginx configuration file points to the same location as the bind is:
Any cloud on what am I doing wrong?
This is not worthy of an answer but I don't have the reputation to comment:
Your docker command maps 8082:80 but you're using port 8083 in the browser.
Is there a chance you're interacting with the wrong container?
I have a container with code in it. This container runs on production server. How can I share folder with code in this container to my local machine? May be with Samba server and then mount (cifs) this folder with code on my machine? May be some examples...
Using
docker cp <containerId>:/file/path/within/container /host/path/target
you could copy some data from the container. If the data in the container and on your machine need to be in sync constantly I suggest you use a data volume to share a directory from your server with the container. This directory can then be shared from the server to your local machine with any method (e.g. sshfs)
The docker documentation about Manage data in containers shows how to add a volume:
$ docker run -d -P --name web -v /webapp training/webapp python app.py
The data from you severs training/webapp location will then be available in the docker container at /webapp.
I've got an AngularJS application running on nginx in container1. When it hits "/api" it gets proxied over to Docker container2 (a PHP API running on Apache). The PHP API accesses my database that is running locally on Mac OS X. Docker containers are Ubuntu.
Communication between containers is very slow. Any idea why?
boot2docker start
docker run -d -h docker --name container2 -v ~/container2dir/:/var/www -p 5000:80 seanbollin/image2
docker run -d -h docker --link name:api -v ~/somefolder/:/var/www/anotherfolder/ -p 5001:80 seanbollin/image1
This could be due to the size of the mounted directory from "File Sharing" section.
I had a 50GB around folder shared having all my projects.
I shared the parent folder just to save some time, but it caused the slowness in http responses.
Share only required folder, and use the .dockerignore for any folder that you don't want to mount, ex. "venv" etc.
I have mysql server running in centos host and I want to deploy my war in tomcat inside docker container in same host. Any idea how can I connect mysql from inside the container.
Here is what you can do to connect to the DB (mysql) from the App (tomcat).
There are two ways you can do this
By using links
Manual way by providing the IP address of db to the tomcat app
Example-1 (Links)
Get your mysql container up:
"docker run --name db -e MYSQL_ROOT_PASSWORD="xxxx" -e
MYSQL_DATABASE="xxxx" -d mysql"
You now need to build and run the application container which must
know where is the db instance. You will have to figure out where you
provide the link to the db in your application. It can be in the code
or in a property file. You can use volume to mount this file into the
application container. You will also be able to modify them on the
fly because they will be accessible to you on the host system. This
is one example of doing this: docker
docker run -d -p 8080:8080 --name app --link db:db -v
$PWD/webapp:/var/lib/tomcat7/webapps/ app
Here we are using the image app where i am mounting webapp folder
from my docker base folder. This folder is having my code which i am
pushing to the tomcat's webapp folder. I am also pushing the
properties file to the appropiate location on the container where the
mysql connection is mentioned like this :
"jdbc.url=jdbc:mysql://db:3306/dbname" . We are mapping port 8080 of
the container to the port 8080 of the host. We are mapping container
db with container app. This creates an entry on /etc/hosts file - "db
ipname". So both containers can communicate with each other even if
we restart the db container (which changes the IP). Links will update
the host entry with the new IP.
Example 2:
Up the db container
Get the IP of the db container using this "docker inspect -f '{{ .NetworkSettings.IPAddress }}' container-name/ID"
Up the app containers with volumes where you can edit the jdbc url on your host.
Change the IP to db container's IP and this should be able to establish the connection
If you want to use Host's mysql
docker run -d --net=host --name app image command
Do let me know if you need any further explanation.
You can go through the topics on volumes, links from docker documentation: https://docs.docker.com/