Docker build step name cannot start with number

Viewed 254

I'm building a docker image for a Sybase database. Docker build command fails because the name of the build step "server" cannot start with a number.

I have searched A LOT for a way to change the build step machine's name and my solution so far is to retry the build until I get a name that starts with a letter...

Step 1/7 : FROM my_image as docker_sybase_db
 ---> d266899b4eef
Step 2/7 : COPY *.zip /mnt/backup/
 ---> Using cache
 ---> 9e8e405848ce
Step 3/7 : COPY entrypoint.sh ~
 ---> Using cache
 ---> 5c0c923985db
Step 4/7 : ENV HOSTNAME docker_sybase_db
 ---> Using cache
 ---> f2b39a7280a0
Step 5/7 : RUN init_db.sh
 ---> Running in 0ae1a95b3203
Server name '0ae1a95b3203' begins with an illegal character.  The first
character of a server name must be an alphabetic ascii character.
Error running command 'srvbuild -r /tmp/my_super_build.rs': 

If I can't modify this old sybase init script, am I out of luck here ?

EDIT: Here is what I am trying to do

  1. Create a database instance
  2. Load a backup
  3. Package that pre-loaded instance into a container.

Loading the backup takes a lot of time and this old database system requires the server name to start with a letter, not a number.

1 Answers

You could try and see if LolHens's idea of changing the hostname in the container namespace (during the docker build) works for you.

docker build . | tee >((grep --line-buffered -Po '(?<=^change-hostname ).*' || true) | \
                       while IFS= read -r id; do \
                         nsenter --target "$(docker inspect -f '{{ .State.Pid }}' "$id")"\
                                 --uts hostname 'new-hostname'; \
                       done)

The docker build output is parsed to:

That means your RUN step should be:

RUN echo "change-hostname $(hostname)"; \
    sleep 1; \
    printf '%s\n' "$(hostname)" > /etc/hostname; \
    printf '%s\t%s\t%s\n' "$(perl -C -0pe 's/([\s\S]*)\t.*$/$1/m' /etc/hosts)" "$(hostname)" > /etc/hosts; \
    init_db.sh

That way, init_db.sh should run in an intermediate container with a different hostname (one you do have control over, and which would not start with a number).

Related