Docker Development Environment – Getting Started (DDE Part 7)

Getting Started

Here are the answer to some common questions to help you when getting started.

Where do you put your web application files?

All files that are going to be served by your web server are placed in project/web directory. This will be different if you changed the PROJECT_NAME and/or WEBSITE_DIR values. We can use tools like PHP Storm to edit these files on our local machine and the files are automatically updated inside the container.

How do I connect to my containers?

$ docker-compose exec container-name bash

So, run the following to connect to the NGINX container:

$ docker-compose exec nginx bash

 The PHP-FPM container also allows you to connect to it with SSH. Connecting to a container via SSH is usually not best practice. But, on Windows, connecting to a container using the above command (docker-compose exec php-fpm bash) has had issues because Windows does not support interactive mode. And, even though this has improved with the current version of Docker, 1.13.0, it is much easier to SSH into the PHP-FPM container. Also, this is a development environment and not used for production. So, it should not be an issue.

Why should I connect to the PHP-FPM container?

One reason to use a virtual machine or a Docker container is to keep the host machine as clean as possible. When we log into the PHP-FPM container, we can use git, composer, npm, bower, yarn, gulp, etc. without having them installed on our host machine.

How do I connect to the database?

With a MySQL client

Hostname:  localhost or project.local

User:  root

Password: root

Port: 3306

From withing the PHP-FPM container

$ mysql -u root -p --host=mysqldb

From Drupal or Symfony

Use mysqldb as the hostname.

Can I use phpMyAdmin?

Yes! But, you have to create a phpMyAdmin container first. You can do this by adding the following to the docker-compose.yml file:

  image: phpmyadmin/phpmyadmin
    - "8080:80"
    PMA_HOST: mysqldb

Then, stop all containers and start them again.

$ docker-compose stop
$ docker-compose up --build

Then, visit http://project.local:8080.

Useful Commands

List containers

$ docker-compose ps

Create and start containers

$ docker-compose up
  • Add –build to make sure the containers are rebuilt.
  • Add -d to have the command prompt returned to use so you can run more commands.

Stop containers

$ docker-compose stop

Start containers

$ docker-compose start

Connect to a container

$ docker-compose exec container-name bash


Sometimes you just need to clean things up. These things will stop and remove containers.

$ docker stop $(docker ps -aq)
$ docker-compose rm -f
$ docker rm -f $(docker ps -aq)
$ docker rmi -f $(docker images -aq)

Summing It Up

You should now have a development environment that you use to develop your web applications. Hopefully, this series of post has not only provided you a docker-base development environment that can be used for development but also some useful information so that you can expand upon it or build your own.

You can find the complete source code for this environment on GitHub.

Leave a Reply

Your email address will not be published. Required fields are marked *