A Dockerfile for Symfony Web container: Nginx, PHP-FPM…
This configuration is built for development. You can use it in production at your own risks !
Install Docker (Boot2docker or Kitematic for OS X & Windows).
Then, run following command to run container:
docker run -d -P vincentchalamon/symfony
Your project is available at http://127.0.0.1 (for Boot2docker, follow http://192.168.59.103).
Want to integrate it with MySql ? I recommand to use Docker Compose.
Create docker-compose.yml
file as following:
web:
image: vincentchalamon/symfony
volumes:
- .:/var/www
net: "host"
tty: true
mysql:
image: mysql
net: "host"
environment:
MYSQL_DATABASE: symfony
MYSQL_USER: root
MYSQL_ALLOW_EMPTY_PASSWORD: yes
Then run docker-compose up -d
, your Symfony project is ready to access MySql through 127.0.0.1:3306
.
By default, web container run on port 80, mysql container on port 3306. But in some case (for example to prevent ports conflicts on Linux), you may need to use customize ports.
Let's imagine we'll run Nginx on port 8888, and MySql on port 3386. Update your docker-compose.yml
file as following:
web:
image: vincentchalamon/docker-symfony
ports:
- 8888:80
volumes:
- .:/var/www
tty: true
db:
image: mysql
command: mysqld --port 3386
net: "host"
environment:
MYSQL_DATABASE: erb_api
MYSQL_USER: root
MYSQL_ALLOW_EMPTY_PASSWORD: yes