Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Save luislard/35b771cd1742c4bafa9deb893906b90e to your computer and use it in GitHub Desktop.
Save luislard/35b771cd1742c4bafa9deb893906b90e to your computer and use it in GitHub Desktop.
Create new Symfony project using composer from docker-container.

Installing a fresh new Symfony Project without having to install PHP on your host.

To achive our goal we will use composer from official docker container.

Of course using docker image will require us to write very long shell commands, but that can be avoid adding the following snippet to our .bashrc or .zshrc*.

  1. Go to your .bashrc and copy paste the following function at the end of the file.
~ $ nano ~/.bashrc

...
# composer function starts
composer () {
    tty=
    tty -s && tty=--tty
    docker run \
        $tty \
        --interactive \
        --rm \
        --user $(id -u):$(id -g) \
        --volume /etc/passwd:/etc/passwd:ro \
        --volume /etc/group:/etc/group:ro \
        --volume $(pwd):/app \
        composer "$@"
}
# composer function ends

Exit using Ctrl + x.

  1. Now you need to restart your bash session closing the terminal or you can use the following command.
~ $ source ~ /.bashrc

Now, you can use composer command and under the hood it will be calling the docker container.

  1. Create the project
~ $ composer create-project symfony/framework-standard-edition project_name 3.4.*
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment