Featured image of post Getting Started with Docker and Docker-Compose

Getting Started with Docker and Docker-Compose

Beginner's Guide to Docker, Stepping into the Cloud Era

Docker

  • You can directly pull an image using the command (take nginx as an example):
    docker pull nginx  
    

Dockerfile

  • Essentially a text file describing how an image is built.
  • After writing a Dockerfile, execute docker build to construct the image based on the instructions.
  • Built images can be pushed to repositories, with Docker Hub being the most commonly used official repository.

Docker Compose

  • Docker prefers splitting services into separate containers for easier management and partial rebuilding when environments change (compared to bundling everything in a single container).

First Steps

  • Run docker pull php-fpm, then execute commands like apt and docker-php-ext-enable directly in the container.
  • Note: The php-fpm image is built on Ubuntu. Check its Dockerfile to see available commands.

LaraDock Pitfalls and Solutions

  • The php-worker container cannot write logs directly to the project. Consider using Redis instead.

Configuring Supervisor in laradock with php-worker

  • The php-worker container doesn’t have bash access (unlike other containers).
  • Supervisord automatically keeps processes alive based on configurations when the php-worker container starts.
  • After modifying supervisord configurations, rebuild the container:
    docker-compose build php-worker && docker-compose up -d php-worker  
    
  • If using Redis as the queue driver, install it in the php-worker container by setting .env:
    PHP_WORKER_INSTALL_REDIS=true