Skip to content

Using thecodingmachine docker images with podman

I wanted to quickly develop something. I thought this is the perfect timing to migrate mentally from the insecure and almost dead docker to the alive and secure podman.

I went to the page of thecodingmachine and tried it with the following one-liner:

podman run -p 80:80 --rm --name php-bazzline -v "$PWD":/var/www/html thecodingmachine/php:7.4-v3-apache

Sadly nothing is working so I've created a feature request asking for podman support.

My current workaround is following

sudo -c "echo '<username>:100000:65536' >> /etc/subuid"
sudo -c "echo '<username>:100000:65536' >> /etc/subgid"
sudo reboot

And adapt the start up as following to prevent port issues (you are not allowed - by default - to use ports below 1024).

podman run -p 8080:80 --rm --name php-bazzline -v "$PWD":/var/www/html thecodingmachine/php:7.4-v3-apache

Thats it.

Create php repository and want to quickly develop and test it everywhere? Add a fanzy start_docker_container.sh shell script to it!

I have to maintain a big bunch of repositories with different languages and different language versions.

After some iterations, I came up with a simple idea by using docker for it. To ease up things for any kind of users who have to deal with this code (even qa), the last iteration is to add a "startdockercontainer.sh" script into the repository.

Following an example script for a php repository.
Given is, that the script is located in <project_root>/bin.
Given is, that the docker file exists in <project_root>/data/docker.

#!/bin/bash
####
# Starts a fitting container and creates image if needed.
#
# @todo
####
# @author stev leibelt <artodeto@bazzline.net>
# @since 2018-05-09
####

PATH_OF_THIS_SCRIPT=$(cd $(dirname "$0"); pwd)
DOCKER_IMAGE_NAME='my_php_application'
DOCKER_IMAGE_TAG='0.1.0'

if ! (docker image ls | grep -q "${DOCKER_IMAGE_NAME}\s\+${DOCKER_IMAGE_TAG}")
then
    PATH_TO_THE_DOCKER_SOURCE=$(realpath ${PATH_OF_THIS_SCRIPT}/../data/docker)
    echo ":: We have to build the docker container first."
    echo ":: Please do the following steps first."
    #this is usefull since you have to copy some ssh keys to a path
    # or configure some files.

    read -p ":: Hit <ENTER> to continue."                                                                                                                       

    docker build -t ${DOCKER_IMAGE_NAME}:${DOCKER_IMAGE_TAG} ${PATH_TO_THE_DOCKER_SOURCE}
fi

docker container run --mount type=bind,source="${PATH_OF_THIS_SCRIPT}"/..,target=/application -it ${DOCKER_IMAGE_NAME}:${DOCKER_IMAGE_TAG} /bin/ash

And thats it. If the image is not found on the host, we have to setup things and build the image. Afterwards we start the container and mount the repository code into /applicationof the container.

PHP UserGroup Hamburg - 2016-02-09 - Dockerizing PHP Applications

Following some notes about my the last php usergroup meetup.

By Sebastian Heuer

  • docker is not one tool but a whole ecosystem
    • machine (provisioning)
    • swarm (clustering and container scheduling)
    • compose (multi container application)
    • registry (image distribution)
    • engine (the container)
    • ktematic (gui)
  • pretty small compared to virtual box/full virtual machines
  • updating means, building a new container
  • theoretically, you can use all the images from the hub
    • always ask yourself if you want to use them in production
      • are they maintained
      • how secure are they
  • docker compose
    • builds and pulls images
    • runs containers
    • enables networking between containers
    • aggregates STDOUT and STDERR output

example Dockerfile

FROM php:7.0.2-fpm

RUN docker-php-ext-install pdo pdo_mysql

COPY php/php.ini /usr/local/etc/php/
# copy the content of the source code into the image
# you can ship this code version now
COPY . /srv/meetup-service

# the date in the container is not persistent
# if ypu change something in it, it will bill lost afterwards

CMD ["php-fpm"]

example docker-compose.yml

webserver:
  build: ./nginx    #path to the docker file and configuration etc
  links:
    - application
  ports:
    - "80:80"   #from port 80 to port 80
  volumes_from:
    - application
application:
  build: ./meetup-service   #your project
  links:
    - database
  ports:
    - "9000:9000"
  volumes:
    - ./meetup-service:/srv/meetup-service  #mounting local source code into the container
  environment:
    - MYSQL_HOST=database
    - MYSQL_DATABASE=application
    - MYSQL_USER=root
    - MYSQL_PASSWORD=parola
database:
  image: mysql:5.7  #no build path, instead an image is used
  volumes:
    - /var/lib/mysql
  ports:
    - "3306:3306"
  environment:
    - MYSQL_ROOT_PASSWORD=docker
    - MYSQL_DATABASE=app