Skip to content

Generate a fresh Symfony application with the Docker configuration.

License

Notifications You must be signed in to change notification settings

jprivet-dev/symfony-starter

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

35 Commits
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Symfony starter

Presentation

Generate a fresh Symfony application with the Docker configuration (Symfony Docker).

This project is a variant of https://github.com/jprivet-dev/symfony-starter-compose-in-another-dir.

Prerequisites

Be sure to install the latest version of Docker Engine.

Installation

The very first time

All in one:

git clone [email protected]:jprivet-dev/symfony-starter.git \
&& cd symfony-starter \
&& make generate

Clean all and generate again:

make stop     # 1. Stop the container
make clean    # 2. Remove all generated files
make generate # 3. Generate again

The following times

make start    # Start the project
make stop     # Stop the project
make restart  # Stop and start the project
make install  # Install all (for example, after an update of your curent branch)

Run make to see all shorcuts for the most common tasks.

Structure

Before make generate:

./
├── overload/
├── scripts/
├── aliases
├── LICENSE
├── Makefile
└── README.md

After make generate:

./
├──*bin/
├──*config/
├──*docs/
├──*frankenphp/
├── overload/
├──*public/
├── scripts/
├──*src/
├──*var/
├──*vendor/
├── aliases
├──*compose.override.yaml
├──*compose.prod.yaml
├──*composer.json
├──*composer.lock
├──*compose.yaml
├──*Dockerfile
├── LICENSE
├── Makefile
├── README.md
└──*symfony.lock 

(*) Fresh Symfony application with a Docker configuration

Save the generated Symfony application

  1. Remove the following block from frankenphp/docker-entrypoint.sh :
	# Install the project the first time PHP is started
	# After the installation, the following block can be deleted
	if [ ! -f composer.json ]; then
		rm -Rf tmp/
		composer create-project "symfony/skeleton $SYMFONY_VERSION" tmp --stability="$STABILITY" --prefer-dist --no-progress --no-interaction --no-install
		# ...
	fi
  1. git add . && git commit -m "Fresh Symfony application"

Makefile: variables overloading

You can customize the Docker build and up processes. To do this, create an overload/.env file and override the following variables :

# overload/.env

# See https://docs.docker.com/compose/how-tos/project-name/
PROJECT_NAME=my-project

# See https://github.com/dunglas/symfony-docker/blob/main/docs/options.md#docker-build-options
COMPOSE_UP_SERVER_NAME=my.localhost
COMPOSE_UP_ENV_VARS=SYMFONY_VERSION=6.4.* HTTP_PORT=8000 HTTPS_PORT=4443 HTTP3_PORT=4443

# See https://docs.docker.com/reference/cli/docker/compose/build/#options
COMPOSE_BUILD_OPTS=--no-cache

These variables will be taken into account by the make commands.

As the variables are common to the Makefile and docker compose, I'm not attaching an environment file with the --env-file option at the moment. See https://docs.docker.com/compose/how-tos/environment-variables/.

Troubleshooting

Error "address already in use" or "port is already allocated"

On the docker compose up, you can have the followings errors:

Error response from daemon: driver failed programming external connectivity on endpoint symfony-starter-php-1 (...): Error starting userland proxy: listen tcp4 0.0.0.0:80: bind: address already in use

Error response from daemon: driver failed programming external connectivity on endpoint symfony-starter-php-1 (...): Bind for 0.0.0.0:443 failed: port is already allocated

Solution #1 - Custom HTTP ports

See https://github.com/dunglas/symfony-docker/blob/main/docs/options.md#using-custom-http-ports.

Overload COMPOSE_UP_ENV_VARS in overload/.env:

COMPOSE_UP_ENV_VARS=HTTP_PORT=8000 HTTPS_PORT=4443 HTTP3_PORT=4443

Solution #2 - Find and stop the container using the port

List containers using the 443 port:

docker ps | grep :443
c91d77c0994e   app-php   "docker-entrypoint f…"   15 hours ago   Up 15 hours (healthy)   0.0.0.0:80->80/tcp, :::80->80/tcp, 0.0.0.0:443->443/tcp, :::443->443/tcp, 0.0.0.0:443->443/udp, :::443->443/udp, 2019/tcp   other-container-php-1

And stop the container by ID or by NAME:

docker stop c91d77c0994e
docker stop other-container-php-1

It is also possible to stop all running containers at once:

make docker_stop_all

Solution #3 - Find and stop the service using the port

See the network statistics:

sudo netstat -pna | grep :80
tcp6       0      0 :::80        :::*        LISTEN        4321/apache2

For example, in that previous case 4321/apache2, you can stop Apache server:

sudo service apache2 stop

Editing permissions on Linux

If you work on linux and cannot edit some of the project files right after the first installation, you can run in that project make permissions, to set yourself as owner of the project files that were created by the docker container.

See https://github.com/dunglas/symfony-docker/blob/main/docs/troubleshooting.md

Resources

Comments, suggestions?

Feel free to make comments/suggestions to me in the Git issues section.

License

This project is released under the MIT License.

About

Generate a fresh Symfony application with the Docker configuration.

Resources

License

Stars

Watchers

Forks