Full Blog TOC

Full Blog Table Of Content with Keywords Available HERE

Sunday, April 27, 2025

Docker Args


This is a short post I want to publish for spending about an hour for weird docker arg issue.

I used the following Dockerfile:

ARG dockerCacheRepo
FROM ${dockerCacheRepo}python:3.12-slim

Then I run the docker build command:

docker build --progress=plain --build-arg dockerCacheRepo=my-repo.com/  .


An indeed I see the argument is used:

#2 [internal] load metadata for my-repo.com/python:3.12-slim


But then I want to use the argument in other locations in the Dockerfile, for example:

ARG dockerCacheRepo
FROM ${dockerCacheRepo}python:3.12-slim
RUN echo "arg is ${dockerCacheRepo}"


But I get:

#0 building with "default" instance using docker driver

#1 [internal] load build definition from Dockerfile
#1 transferring dockerfile: 134B done
#1 DONE 0.0s

#2 [internal] load metadata for my-repo.com/python:3.12-slim
#2 DONE 0.1s

#3 [internal] load .dockerignore
#3 transferring context: 2B done
#3 DONE 0.0s

#4 [1/2] FROM my-repo.com/python:3.12-slim@sha256:85824326bc4ae27a1abb5bc0dd9e08847aa5fe73d8afb593b1b45b7cb4180f57
#4 CACHED

#5 [2/2] RUN echo "arg is ${dockerCacheRepo}"
#5 0.186 arg is
#5 DONE 0.2s


What?

Why is the argument reset?


After banging my head in the wall for a while I've found the working version:

ARG dockerCacheRepo
FROM ${dockerCacheRepo}python:3.12-slim
ARG dockerCacheRepo
RUN echo "arg is ${dockerCacheRepo}"

And then:

#0 building with "default" instance using docker driver

#1 [internal] load build definition from Dockerfile
#1 transferring dockerfile: 155B done
#1 DONE 0.0s

#2 [internal] load metadata for my-repo.com/python:3.12-slim
#2 DONE 0.6s

#3 [internal] load .dockerignore
#3 transferring context: 2B done
#3 DONE 0.0s

#4 [1/2] FROM my-repo.com/python:3.12-slim@sha256:85824326bc4ae27a1abb5bc0dd9e08847aa5fe73d8afb593b1b45b7cb4180f57
#4 CACHED

#5 [2/2] RUN echo "arg is my-repo.com/"
#5 0.137 arg is my-repo.com/
#5 DONE 0.2s


This is real bad design in docker.

The idea is that any arg that is configured is forgotten after the "FROM" command, and then it must be redefined. I guess the designers has a multi-stage docker build in mind when planning this, but i think this is a mistake. Anyway, I hope this saves some time for anyone who bumps into the same issue.






Monday, April 21, 2025

Using VectorScan In GO

 

In this post we will review how to prepare the environment to use VectorScan in Go.


VectorScan is a fork of Intel's HyperScan supplying a high-performance multiple regex matching.

Using it in GO, can be quite cumbersome due to need to link with the C library.

Listed below is a Dockerfile displaying the step to do it:

FROM golang:1.23.0

# build the VectorScan
RUN apt update
RUN apt install -y git build-essential cmake ragel pkg-config libsqlite3-dev libpcap-dev libboost-all-dev
WORKDIR /
RUN git clone https://github.com/VectorCamp/vectorscan.git
WORKDIR /vectorscan
RUN git checkout vectorscan/5.4.11
WORKDIR /vectorscan/build
RUN cmake ../ -DBUILD_SHARED_LIBS=On
RUN make -j 6


# Run the gohs example linked with the VectorScan

COPY ./src/go.mod /src/
COPY ./src/go.sum /src/
WORKDIR /src
RUN go mod download

ADD ./src /src
RUN export PKG_CONFIG_PATH=/vectorscan/build/:/vectorscan/build/lib:$PKG_CONFIG_PATH &&CGO_CFLAGS="-g -O2 -I/vectorscan/src -I/vectorscan/build" CGO_LDFLAGS="-lhs -L/vectorscan/build/ -L/vectorscan/build/lib" GOOS=linux go build -o /regex

RUN export LD_LIBRARY_PATH=/vectorscan/build/lib:$LD_LIBRARY_PATH && echo ${LD_LIBRARY_PATH} && /regex


The first step install the VectorScan build related tools, download the VectorScan library GIT, and compiles it.


The second step uses GoHS which is wrapper for the VectorScan library.
The main.go is simply the example in gohs.

I've spent a couple of hours figuring the problems here, so I put in in this post in case it would assist anyone else.