DEV Community

Cover image for Symfony 5 development with Docker

Symfony 5 development with Docker

Martin Pham on December 30, 2019

We were playing with Kubernetes last week, however the project was just a small PHP file with phpinfo() function call, no big deal. Today my colle...
Collapse
 
danseely profile image
Dan Seely •

Great writeup! This is going to help me out a ton.

After reading through the article and looking at your example repo, I think the directory structure at the top of this article would look more like this (i.e. dedicated docker and src directories):

Project
│
├── docker
├──── docker-compose.yml
│
├──── database/
│   ├──── Dockerfile
│   └──── data/
│
└──── php-fpm/
│   └──── Dockerfile
│
├──── nginx/
│   ├──── Dockerfile
│   └──── nginx.conf
│
└──── logs/
│   └──── nginx/
├── src
├──── <Symfony app>
Enter fullscreen mode Exit fullscreen mode
Collapse
 
b3nb1 profile image
b3nb1 • • Edited

For those which rather want to use postgresql instead of mariadb.

# docker/database/Dockerfile
FROM postgres:latest

ENV POSTGRES_USER <your user>
ENV POSTGRES_PASSWORD <your password>
EXPOSE 3306

And I had to add

RUN apk add --no-cache bash

in php-fpm dockerfile (due to this warning: env: can't execute 'bash': No such file or directory).

Collapse
 
eelcoverbrugge profile image
Eelco Verbrugge •

Greatly explained setup, thanks! How to downgrade php to 7.4? I tried replacing the first line in docker/php-fpm/Dockerfile to FROM php:7.4-fpm-alpine and fired up my container but didn't work. docker exec -it docker_php-fpm_1 php -v outputs PHP 8.0.9 (cli). Any thoughts?

Collapse
 
samikerb profile image
samikerb •

Hello,

thank you for this amazing post,

i have an issue with login, once i submit to login i got this error :

php-fpm_1 | [21-Sep-2020 16:45:16] WARNING: [pool www] child 38 exited on signal 9 (SIGKILL) after 318.447129 seconds from start
php-fpm_1 | [21-Sep-2020 16:45:16] NOTICE: [pool www] child 50 started

any idea ?

Collapse
 
samikerb profile image
samikerb •

2020/09/21 16:48:50 [error] 29#29: *37 recv() failed (104: Connection reset by peer) while reading response header from upstream, client: 192.168.0.1, server: localhost, request: "POST /login HTTP/1.1", upstream: "fastcgi://192.168.0.3:9000", host: "localhost:1609", referrer: "localhost:1609/login"

Collapse
 
abelardoit profile image
abelardoit • • Edited

Hi there!
I am a beginner developer. I downloaded your project from your repo for learning purposes.
I use Maker Bundle to automatically create an user.
When I run the command (docker and mysql are already running):
php bin/console make:migration

this error is shown several times in a row:
SQLSTATE[HY000] [2002] php_network_getaddresses: getaddrinfo failed: Temporary failure in name resolution

Could be possible that this bundle is unable to know where my database is running? How could I solve this issue?

Any help would be welcome. Thanks for your excellent article and cheers.

Collapse
 
fadilxcoder profile image
fadilxcoder •

You should connect to you docker terminal to run the above command... It should be something like docker exec -it docker_container_name ash. Your docker_container_name should be listed in docker ps -a

Collapse
 
jdf1976 profile image
jdf1976 •

Hello nice Tutorial.
I gott a Error while Docker-compose

=> ERROR [stage-0 2/7] COPY wait-for-it.sh /usr/bin/wait-for-it 0.0s

[stage-0 2/7] COPY wait-for-it.sh /usr/bin/wait-for-it:

failed to compute cache key: "/wait-for-it.sh" not found: not found
ERROR: Service 'php-fpm' failed to build

can someone help me to solve that problem?

Collapse
 
1n53c profile image
Rene Glasow •

Please have a look at the Gitlab Repo mentioned in the article. There you will find the wait-for-it.sh. You have to add it to your code. It's not included in the article.

Collapse
 
stevencarre profile image
Steven Carré •

Hi, great post!
this is where i get an error:
when i try docker-compose up, i get this error
Error starting userland proxy: listen tcp 0.0.0.0:80: bind: address already in use
What am I doing wrong?
Any help appreciated

Collapse
 
bronkes profile image
bronkes •

UPDATE 31.07.2021
if someone having the problem with error from apline:
/bin/sh: Operation not permitted
or
*some_command* returned a non-zero code: 2

just change first line in docker/php-fpm/Dockerfile to:
FROM php:8.0-fpm-alpine3.13

They mess something in update 3.14, changing to older version fixes that

Collapse
 
arthurguillerm profile image
Arthur Guillerm •

Excellent article !

Collapse
 
martinpham profile image
Martin Pham •

Thanks! Glad you liked it!

Collapse
 
naezeroth profile image
naezeroth •

Wonderful post! I was wondering how one would deploy something like this on AWS/Azure?

Collapse
 
bkrnetic profile image
bkrnetic •

Great article!

Would be great if I was able to enter container bash by running

docker-compose exec nginx bash
Enter fullscreen mode Exit fullscreen mode

Is it possible to update Dockerfile to enable that?

Collapse
 
nawaaugustine profile image
Nawa Augustine •

You can try

docker exec -it nginx sh

Collapse
 
cyrilcharlier profile image
CyrilCharlier • • Edited

Great tutorial !
Just one thing, remember to add "wait-for-it.sh" in "php-fpm" directory ;)

Collapse
 
galgaldas profile image
Galgaldas •

If you prefer apache over nginx and you need phpmyadmin, mysql, email dockerized services, I would recommend checking this repository - github.com/kasteckis/symfony-docke...

Collapse
 
eiosca profile image
eiosca •

Thk's a lot for this article, simple and functional. +1