Docker – Beginner’s Notes

Well, after a year returning to Docker, I can still be considered as a beginner since I forgot almost things that I did before :shame: So this entry, Docker – Beginner’s Notes, is just a way that helps me in the future (hopefully).

  1. Useful commands to remember: docker images, docker ps -a, docker rm <container_name>, docker rmi <image_name>
  2. For docker-compose, useful commands are: docker-compose up -d, docker-compose down, docker-compose stop/start
  3. If you want to enter a container, use docker exec -ti as follows:
    docker exec -ti <container_name> /bin/bash
  4. If you use PDO for connecting to MySQL, remember to include it into your PHP build environment (docker-php-ext-install pdo pdo_mysql), otherwise you will not be able to connect to your DB server.
  5. In case we want to update the docker containers to latest version, we will need to go with 2 steps
    1. Pull the latest image version. E.g.
    2. Remove the old containers and run docker again to force docker to rebuild containers based on new images. If you are using docker-compose, then we can simply rebuild all containers with
    3. Remove old docker images. You can use docker images to list all available images and remove out-dated ones with the following command

       

My sample docker-compose.yml is as follows:

Sample ./php/Dockerfile is as follows:

FROM php:7.1-fpm
RUN apt-get update && apt-get install -y \
        libfreetype6-dev \
        libjpeg62-turbo-dev \
        libmcrypt-dev \
        libpng12-dev \
        libxml2-dev \
        curl libcurl4-openssl-dev apt-utils wget nano telnet \
    && sed -i "s|;*listen\s*=\s*127.0.0.1:9000|listen = 9000|g" /usr/local/etc/php-fpm.d/www.conf \
    && sed -e 's/;clear_env = no/clear_env = no/' -i /usr/local/etc/php-fpm.d/www.conf \
    && docker-php-ext-install -j$(nproc) iconv mcrypt mysqli mbstring opcache \
    && docker-php-ext-install -j$(nproc) gd xml json pdo pdo_mysql zip curl \
    && pecl install redis && docker-php-ext-enable redis
RUN curl -sS https://getcomposer.org/installer | php -- --install-dir=/usr/local/bin --filename=composer
RUN composer global require "laravel/installer"
## NodeJS, NPM -- Install NodeJS
RUN curl -sL https://deb.nodesource.com/setup_6.x | bash -  && apt-get install -y nodejs
ENV PATH ${PATH}:~/.composer/vendor/bin
COPY ./ext/ioncube_loader_lin_7.1.so /usr/local/lib/php/extensions/no-debug-non-zts-20160303
COPY ./ext/00_docker-php-ext-ioncube_loader.ini /usr/local/etc/php/conf.d/
COPY ./docker-php-settings-uploads.ini /usr/local/etc/php/conf.d/

If we choose apache as the webserver instead of nginx, the sample docker-compose-apache.yml is as follows:

Leave a Reply