I'm just starting to get my head around docker and want to use it for a project.
I have followed https://docs.docker.com/docker-for-mac/#explore-the-application-and-run-examples and have NGINX running fine and can see the NGINX landing page.
Do I need to install php-fpm and mySQL within my container since my container is only NGINX at this stage?
How do I configure my project on a custom domain e.g. project.dev. Do I need to edit an entry in /etc/hosts for 127.0.0.1 project.dev and then listen for that URL in an NGINX config?
Lastly do I need a dockerfile? I already have my container up and my understanding is a dockerfile is only for defining your container?
An example of a dockerfile for NGINX, PHP and mySQL would be helpful to look at as well.
Thanks
No, this guide just show using nginx container in docker. But I see the container don't have php installed. And you cannot install php-fpm inside this container.
So, if you want to use nginx, php, and MySQL using docker you should pull:
Container which run Nginx + PHP-FPM (I recommend this image https://hub.docker.com/r/richarvey/nginx-php-fpm/)
Container run MySQL (https://hub.docker.com/_/mysql/)
Download images
docker pull richarvey/nginx-php-fpm
docker pull mysql:5.6
Run MySQL Instance. Name it mysql56, and expose using port 3360
docker run -tid -p 3360:3306 --name mysql56 -e MYSQL_ROOT_PASSWORD=123456 -v /root/docker/mysql56/data/mysql:/var/lib/mysql -d mysql:5.6
Run Nginx PHP+FPM instance. Link it to MySQL Instance, and name it project-dev
docker run -tid --name project-dev --link mysql56:mysql -v $(pwd):/var/www/html -p 8888:80 richarvey/nginx-php-fpm:latest
Run docker ps -a to see the running containers.
To make nginx can be accessed with address project.dev, just map it on /etc/hosts. Then access it on web browser http://project.dev:8888
Note:
-v /root/docker/mysql56/data/mysql:/var/lib/mysql it mean I have /root/docker/mysql56/data/mysql on my mac, and map it to /var/lib/mysql in mysql56 container. So all mysql data will be backup on my local data, and will not lose when I remove the container.
-v $(pwd):/var/www/html mean your current directory will be mapped to
container. So, whatever you write in this directory will be exist on
/var/www/html container.
I use port 8888 to avoid conflict with existing web server, you can
change it as you want
Related
I am trying to use Shopware 6 (6.2.0_1589874223) in a Docker (Ubuntu 20.04) container. The installation was successful. Now though all the urls are wrong. They have localhost added to their link, i.e. http://localhost:8080/http://localhost:8080/index.php/account/login
There is one localhost too much. My guess is that it first adds a http://localhost:8080 inside the container and then again outside. Assuming this is right, I would believe that the server name has to be set somewhere.
From the technical perspective I just installed Apache2, MySQL and PHP inside the container and then copy and run the contents of install_6.2.0_1589874223.zip (Community Edition downloaded from the Shopware site) in /var/www/html. I then expose the port 80 from the container and then run the container using this command:
docker run -d -p 8080:80 --name shopware-test -i myshopware/shopware-test:0.0.1
I am developping a website which I want to host inside a php-apache docker container.
I use the following command to run the container:
docker run -dit --restart unless-stopped --name my_www -p 8080:80 -v /path/to/repo:/var/www/html/ php:7.4-apache
Since I bind the repository containing the code as a volume to the container, I expect the website to "update live" when I change the code locally. I had this right behaviour last time I tried but I am now unable to get it back.
When I check the website locally at 127.0.0.1 everything is ok and changes are taken into account normaly, but they do not propagate into the docker container...
For some reason, the files in the docker are stuck to an old version of the code, an old "stat" of the repository...
Any ideas how I can manage to fix this and preview changes live ?
Credits to #Don't Panic for helping to debug.
The browser was caching everything so I couldn't see changes live.
The solution was to enable the "expires" apache module inside the docker container:
$ docker exec -it <container_id> bash
root#<container_id>:# a2enmod expires
root#<container_id>:# exit
$ docker restart my_www
Et voilĂ :)
I am using docker on windows 10 pro and I installed the following
centos
mysql
nginx
The container inside docker and mysql databases is also installed on my host machine.
Now I want to access the datadir folder of host's mysql database from docker centos
container
Map both containers to the same host-volume and both containers should be able to see the data stored there.
Create your volume:
https://docs.docker.com/engine/admin/volumes/volumes/#create-and-manage-volumes
docker volume create mysqldata
Start your containers mapped to the volume: https://docs.docker.com/engine/admin/volumes/volumes/#start-a-container-with-a-volume
docker run -d --mount source= mysqldata,target=/var/lib/mysql mysql
docker run -d --mount source= mysqldata,target=/var/lib/mysql centos
I'm following this guide to set up a PHP development environment with Docker.
I have created a folder on my desktop docker-php and added a docker-compose.yml file into it, with this content:
nginx:
image: nginx:latest
ports:
- 80:80
On my terminal:
$ cd /home/my-username/Desktop/docker-php/
$ docker-compose up -d
I get this error:
ERROR: Couldn't connect to Docker daemon at
http+docker://localunixsocket - is it running?
If it's at a non-standard location, specify the URL with the
DOCKER_HOST environment variable.
I'm on Xubuntu 16.04.
Or perhaps I should put the folder in the specific location that is required by Docker? If so, which is it?
The most common reason for this error is that you ran 'docker-compose up' without sudo. As long as there is docker installed and is up and running, you are likely missing sudo in the docker command.
You could use native Docker
One option is to abandon docker-machine and use a native Docker setup on your system. Since you are on Linux (Xubuntu), this is an option for you. docker-machine is most often used by people who can't run Docker natively (Mac or Windows), and use it to install a Docker-capable VM and some local commands on their OS to talk to it.
You can find install docs for Docker on Linux here.
However, you already have docker-machine installed, so this may be the most disruptive option for you.
Your docker-machine may not be running
The error you are getting is saying the Docker client cannot talk to the server. One potential reason for this is that your docker-machine VM isn't running. You should verify it is running, and if not, start it.
To get a list of your docker-machines (may be one or more):
docker-machine ls
You will probably have one machine named default, but you may have more, depending on how you did your setup.
You can get the current status with:
docker-machine status <machine-name>
And you can use stop, start, restart to manage the docker-machine.
(More in the Docker Machine CLI reference.)
You need the proper environment set
docker-machine relies on environment variables to work properly. Because you may have multiple docker-machine setups, you have to tell the client which one to use.
To set the environment, you can get it from the docker-machine command.
docker-machine env <machine-name>
And you can automatically inject it into the environment (this may be a useful thing to put into your shell startup file).
eval "$(docker-machine env <machine-name>)"
You should end up with env vars similar to these:
DOCKER_HOST=tcp://192.168.99.101:2376
DOCKER_CERT_PATH=/Users/nathanleclaire/.docker/machines/.client
DOCKER_TLS_VERIFY=1
DOCKER_MACHINE_NAME=dev
Keep in mind you should use the eval form here, not just run the env command and paste the output into your shell setup; it may change on a docker-machine restart, etc, so you can't rely on an old setup to still work later.
If your docker-machine is running, and these env vars are set, your docker and docker-compose commands should work.
Solution:
sudo usermod -a -G docker USERNAME
How can I connect to Php container from my Windows machine?
I run docker toolbox https://www.docker.com/products/docker-toolbox on my Windows 10 machine. It's create docker-machine (env default) using virtualbox on port tcp://192.168.99.100:2376 and from host machine (Windows) I can connect to it by ssh. Inside docker-machine I run containers with docker-compose.
I run PhpStorm on Windows and I want to configure PHP interpreter to listen to containerized php. I have read https://confluence.jetbrains.com/display/PhpStorm/Working+with+Remote+PHP+Interpreters+in+PhpStorm but still no sure how to configure it.
I found http://obrown.io/2015/12/23/phpunit-docker-phpstorm.html
The goal create local php script and somehow provide in it connection to php.
In the example author create new container and execute/link php there
End of "docker-machine env default" output
/usr/local/bin/docker run -i --rm -v "${PWD}":"${PWD}" -w ${PWD} --net=host --sig-proxy=true --pid=host originalbrownbear/php:7-cli-phpunit php "$#"
How can I configure such script to use existing docker container with php?
Nornally I enter running container - docker exec -it container_tag_name /bin/bash
And there I can execute php.