Unable to use sed to customize buffer size in mariadb Dockerfile

I’m trying to customize a mariadb container so that it has an increased innodb buffer size. My ideal scenario would be to use sed so I don’t have to maintain a duplicate my.cnf config file.

Here’s my Dockerfile, but it doesn’t replace the value like I’d expect and I”m not sure what I’m doing wrong…

  • Error loading psycopg2 module when installed from a 'wheel'
  • What run flags are included in my Docker Container
  • Does Spark Job Server have to be deployed on the same host as Spark Master?
  • Using multer with express in docker container
  • Linking django and mysql containers using docker-compose
  • Changing path of docker containers in host system
  • FROM mariadb:10.1
    RUN sed -ri 's/innodb_buffer_pool_size\\ =\\ 256M/innodb_buffer_pool_size\\ =\\ 512M/g' /etc/mysql/my.cnf \
        && cat /etc/mysql/my.cnf | grep innodb;

    The output of this is:

    Sending build context to Docker daemon 231.9 MB
    Step 1 : FROM mariadb:10.1
     ---> 9a0138c02438
    Step 2 : RUN sed -ri 's/innodb_buffer_pool_size\\ =\\ 256M/innodb_buffer_pool_size\\ =\\ 512M/g' /etc/mysql/my.cnf     && cat /etc/mysql/my.cnf | grep innodb;
     ---> Running in eaedaf2837ff
    #innodb_log_file_size   = 50M
    innodb_buffer_pool_size = 256M
    innodb_log_buffer_size  = 8M
    innodb_file_per_table   = 1
    innodb_open_files       = 400
    innodb_io_capacity      = 400
    innodb_flush_method     = O_DIRECT
     ---> b0e479c55581
    Removing intermediate container eaedaf2837ff
    Successfully built b0e479c55581

    I’ve tried escaping the spaces with \\ and not escaping the spaces with no luck.

  • Docker max depth exceeded
  • Setting up Nginx Proxy in Docker using Ansible
  • COS is running out of inodes for /var/lib/docker volume
  • Set locale in Docker container
  • Building Docker images using Jenkins results in “Unsupported protocol scheme found”
  • How to clear cache on building Gitlab?
  • One Solution collect form web for “Unable to use sed to customize buffer size in mariadb Dockerfile”

    Just don’t escape the spaces like you do:

    1. spaces don’t need escaping
    2. escaping with \\ inside simple quotes actually create a \ char. No wonder why your regex doesn’t work.

    That works:

    sed -i 's/innodb_buffer_pool_size = 256M/innodb_buffer_pool_size = 512M/g' /etc/mysql/my.cnf
    1. if you really have to escape something, that will be only because of regex, not the shell, because you have used simple quotes and the shell does not interpret the contents
    2. you don’t need the -r, --regexp-extended switch for this particular example. regexp extended includes stuff like forward lookup, … not needed here.

    Improvement: use group to recall the matched value. Less maintenance if you have to change the parameter name

    sed -i 's/\(innodb_buffer_pool_size\) = 256M/\1 = 512M/g' /etc/mysql/my.cnf

    or match several parameter names

    sed -i 's/\(innodb_buffer_pool_size\|some_other_param\) = 256M/\1 = 512M/g' /etc/mysql/my.cnf
    Docker will be the best open platform for developers and sysadmins to build, ship, and run distributed applications.