Docker for Developers (PHP)


Install composer and php, mysql

Docker Compose

Docker Compose is based on an older orchastration tool called ‘Fig2.’ The idea of Fig was to make it easy to define full-stack applications in a single configuration file yet still help maintain the “one process per application” design of Docker. Docker Compose extends this idea into an official tool that will allow you to define how applications are structured into Docker containers while bundling everything up into an easy-to-deploy configuration.

Compose will read a file and build the necessary docker run commands that we need, in the proper order, to deploy our application. Since you should understand how all of this works from a manual process, Compose will just make the work you have done thus far much, much easier.

Compose starts with a docker-compose.yml file which contains all of the information on each container inside of an application, and how it should be configured.

To boot up a Compose configuration, go into the directory containing the docker-compose.yml file, which in our case is in the root directory of our application. We can boot the entire configuration using docker-compose -d up, and we should see something similiar to the following:

7 Command Cheatsheets

7.1 Images

  • docker images – List out all of the images on the host machine
  • docker rmi [image] – Removes a Docker image if no containers are using it
  • docker pull [image][:tag] – Downloads a tag from a registry

7.2 Containers

  • docker ps [-a] – Lists containers currently on the system
  • docker run [options] IMAGE [command] [arguments] – Creates a container and starts it
  • docker start [name] – Starts a running container
  • docker attach [name] – Re-connects to a container that is running in the background
  • docker stop [name] – Stops a running container
  • docker rm [-f] [name] – Removes a container
  • docker create [options] IMAGE [command] [arguments] – Creates a container

7.3 docker-machine

  • docker-machine create --driver [driver] [machinename] – Creates a new Docker Machine
  • docker-machine ls – Lists all of the available machines
  • docker-machine env [machinename] – Returns the information about a machine
  • docker-machine start [machinename] – Starts a stopped machine
  • docker-machine stop [machinename – Stops a running machine
  • docker-machine restart [machinename] – Restarts a machine
  • docker-machine ip [machinename] – Returns the IP of a machine
  • docker-machine rm [machinename] – Destroys a machine
  • docker-machine ssh [machinename] – SSH’s into a machine

7.4 docker-compose

  • docker-compose up -d – Builds a project
  • docker-compose ps – Shows container information for project
  • docker-compose rm – Destroys a project
  • docker-compose stop – Stops a project
  • docker-compose scale [container]=[size] – Adds or removes containers for scaling