Setup Docker Machine for Symfony Development

综合技术 2017-04-28

If you need a development environment for Symfony, hosted by Docker
, you can use the fazy/apache-symfony
docker image to start with, then extend it to your need.

In your Symfony project’s folder add the Dockerfile
and docker-compose.yml
files.

In the first one, we added mysql
and composer
, then we used the docker-compose.yml
file to mount a local volume to the docker container with file sync.

This way you can code on your machine and test in the docker environment.

The Dockerfile
:

FROM fazy/apache-symfony
ADD . /app
 
RUN    apt-get update 
    && apt-get -yq install 
        mysql-server 
        php5-mysql 
    && rm -rf /var/lib/apt/lists/*
 
RUN curl -s https://getcomposer.org/installer | php
RUN mv composer.phar /usr/local/bin/composer
ENV COMPOSER_ALLOW_SUPERUSER 1
RUN service mysql start

The docker-compose.yml
file:

version: "2"
services:
    site:
        build: .
        ports:
            - "8080:80"
        expose:
            - "80"
        volumes:
          - .:/app

To build the Docker container use:

docker
-
compose
up
--
build

To start it when it’s down just remove the –build parameter:

docker
-
compose
up

Once is running, you can view it’s ID by running:

docker
ps

Now grab the first 3 characters from the id and use them in the next command to be able to log in the running container:

docker
exec
-
t
-
i
ID
bash

Finnaly, to access the Symfony project in your browser, go to http://localhost:8080/app_dev.php
and have fun!

IntelligentBee Tech Blog

责编内容by:IntelligentBee Tech Blog (源链)。感谢您的支持!

您可能感兴趣的

Subfinder:一个子域名发现工具,可以为任何目标枚举海量的有效子域名... SubFinder是一个子域发现工具,可以为任何目标枚举海量的有效子域名。它已成为 sublist3r项目 的继承者。SubFinder使...
Using the button instead of the call for action in... Using the loop for an ArrayLIst in Java (Bluej)? ...
奇妙的 Docker 使用技巧十连发!|航海日志 Vol.16... 汇总一周容器圈热点资讯,让开发者了解最 in 的容器技术,让企业熟知最实时的国内外容器行业动态。 奇妙的 Docker 使用技巧十连发 ...
2014 in review: Docker rising When looking back on 2014 from an infrastructure perspective, it’s hard not to ...
What’s new in Docker 17.06 Community Edition (CE)... Docker 17.06 CE (Community Edition) is the first version of Docker built entire...