Issues about build vyos docker image

Hello,

I want to build a docker image for vyos-1.4

I followed this url:

https://github.com/vyos/vyos-build/tree/current/docker-vyos

use this build command:

cd vyos-build/docker

docker build --compress -f Dockerfile -t vyos:1.4-`date -u +%Y%m%d%H%M%S` --build-arg BUILD_DATE="`date -u --rfc-3339=seconds`" --build-arg VYOS_VERSION=1.4 --build-arg DEBIAN_VERSION=bullseye --progress plain .. 

But it failed:

Step 16/66 : RUN curl https://raw.githubusercontent.com/ocaml/opam/master/shell/install.sh       --output /tmp/opam_install.sh --retry 10 --retry-delay 5 &&     sed -i 's/read BINDIR/BINDIR=""/' /tmp/opam_install.sh && sh /tmp/opam_install.sh &&     opam init --root=/opt/opam --comp=${OCAML_VERSION} --disable-sandboxing --no-setup
 ---> Running in 6b884f327cbd
  % Total    % Received % Xferd  Average Speed   Time    Time     Time  Current
                                 Dload  Upload   Total   Spent    Left  Speed
100 28837  100 28837    0     0   385k      0 --:--:-- --:--:-- --:--:--  385k
## Downloading opam 2.1.2 for linux on x86_64...
## Downloaded.
## Where should it be installed ? [/usr/local/bin] ## opam 2.1.2 installed to /usr/local/bin
## Run this script again with '--restore ' to revert.
[WARNING] Running as root is not recommended
No configuration file found, using built-in defaults.
Checking for available remotes: git.
  - you won't be able to use rsync and local repositories unless you install the rsync command on your system.
  - you won't be able to use mercurial repositories unless you install the hg command on your system.
  - you won't be able to use darcs repositories unless you install the darcs command on your system.


<><> Fetching repository information ><><><><><><><><><><><><><><><><><><><><><>
[default] Initialised

<><> Creating initial switch '4.12.0' (invariant ["ocaml-base-compiler" {= "4.12.0"} | "ocaml-system" {= "4.12.0"}]) 

<><> Installing new switch packages <><><><><><><><><><><><><><><><><><><><><><>
Switch invariant: ["ocaml-base-compiler" {= "4.12.0"} | "ocaml-system" {= "4.12.0"}]

<><> Processing actions <><><><><><><><><><><><><><><><><><><><><><><><><><><><>
-> installed base-bigarray.base
-> installed base-threads.base
-> installed base-unix.base
-> installed ocaml-options-vanilla.1
-> retrieved ocaml-base-compiler.4.12.0  (https://opam.ocaml.org/cache)
The command '/bin/sh -c curl https://raw.githubusercontent.com/ocaml/opam/master/shell/install.sh       --output /tmp/opam_install.sh --retry 10 --retry-delay 5 &&     sed -i 's/read BINDIR/BINDIR=""/' /tmp/opam_install.sh && sh /tmp/opam_install.sh &&     opam init --root=/opt/opam --comp=${OCAML_VERSION} --disable-sandboxing --no-setup' returned a non-zero code: 137
root@build:/home/vyos/vyos-build/docker# 

Any suggesions to fix it?

I download vyos-build and build again.

git clone -b current --single-branch https://github.com/vyos/vyos-build
cd vyos-build/
cd docker

docker build --compress -f Dockerfile -t vyos:1.4-`date -u +%Y%m%d%H%M%S` --build-arg BUILD_DATE="`date -u --rfc-3339=seconds`" --build-arg VYOS_VERSION=1.4 --build-arg DEBIAN_VERSION=bullseye --progress plain ..

Following error came out. Any suggestions? Thanks.

Step 19/67 : RUN eval $(opam env --root=/opt/opam --set-root) &&     opam pin add vyos1x-config https://github.com/vyos/vyos1x-config.git#67250430 -y
 ---> Running in e22f4354163a
[WARNING] Running as root is not recommended
[WARNING] Running as root is not recommended
Package vyos1x-config does not exist, create as a NEW package? [Y/n] y
[vyos1x-config.~dev] synchronised (git+https://github.com/vyos/vyos1x-config.git#67250430)
vyos1x-config is now pinned to git+https://github.com/vyos/vyos1x-config.git#67250430 (version 0.2)

The following actions will be performed:
  - install easy-format         1.3.3    [required by yojson]
  - install ppx_derivers        1.2.1    [required by ppx_deriving]
  - install result              1.5      [required by ppx_deriving_yojson]
  - install menhirSdk           20220210 [required by menhir]
  - install ocaml-compiler-libs v0.12.4  [required by ppxlib]
  - install sexplib0            v0.15.0  [required by ppxlib]
  - install menhirLib           20220210 [required by menhir]
  - install cppo                1.6.8    [required by ppx_deriving, yojson]
  - install biniou              1.2.1    [required by yojson]
  - install ppxlib              0.25.0   [required by ppx_deriving_yojson]
  - install menhir              20220210 [required by vyos1x-config]
  - install yojson              1.7.0    [required by vyos1x-config]
  - install ppx_deriving        5.2.1    [required by ppx_deriving_yojson]
  - install ppx_deriving_yojson 3.6.1    [required by vyos1x-config]
  - install vyos1x-config       0.2*
===== 15 to install =====

<><> Processing actions <><><><><><><><><><><><><><><><><><><><><><><><><><><><>
-> retrieved cppo.1.6.8  (https://opam.ocaml.org/cache)
-> retrieved biniou.1.2.1  (https://opam.ocaml.org/cache)
-> retrieved easy-format.1.3.3  (https://opam.ocaml.org/cache)
-> retrieved menhir.20220210  (https://opam.ocaml.org/cache)
-> retrieved ocaml-compiler-libs.v0.12.4  (https://opam.ocaml.org/cache)
-> retrieved ppx_derivers.1.2.1  (https://opam.ocaml.org/cache)
-> retrieved ppx_deriving.5.2.1  (https://opam.ocaml.org/cache)
-> retrieved ppx_deriving_yojson.3.6.1  (https://opam.ocaml.org/cache)
-> retrieved ppxlib.0.25.0  (https://opam.ocaml.org/cache)
-> retrieved result.1.5  (https://opam.ocaml.org/cache)
-> retrieved sexplib0.v0.15.0  (https://opam.ocaml.org/cache)
-> retrieved yojson.1.7.0  (https://opam.ocaml.org/cache)
-> retrieved menhirLib.20220210  (https://opam.ocaml.org/cache)
-> retrieved menhirSdk.20220210  (https://opam.ocaml.org/cache)
-> installed cppo.1.6.8
-> installed easy-format.1.3.3
-> installed menhirLib.20220210
-> installed biniou.1.2.1
-> installed menhirSdk.20220210
-> installed ocaml-compiler-libs.v0.12.4
-> installed menhir.20220210
-> installed ppx_derivers.1.2.1
-> installed result.1.5
-> installed sexplib0.v0.15.0
-> installed yojson.1.7.0



The command '/bin/sh -c eval $(opam env --root=/opt/opam --set-root) &&     opam pin add vyos1x-config https://github.com/vyos/vyos1x-config.git#67250430 -y' returned a non-zero code: 137

I found code 137=128+9

The command '/bin/sh -c eval $(opam env --root=/opt/opam --set-root) &&     opam pin add vyos1x-config https://github.com/vyos/vyos1x-config.git#67250430 -y' returned a non-zero code: 137

The build process was killed because of out of memory.
I upgrade my host machine, and succed to build the docker.

# docker images
REPOSITORY   TAG             IMAGE ID       CREATED        SIZE
vyos         1.4             b64123449599   12 hours ago   162MB
debian       bullseye-slim   bfbec70f8488   11 days ago    80.4MB

However I can’t run it:

docker run -v /lib/modules:/lib/modules --privileged --name vyos_inside_docker -it vyos:1.4
docker: Error response from daemon: failed to create shim: OCI runtime create failed: container_linux.go:380: starting container process caused: exec: "/lib/systemd/systemd": stat /lib/systemd/systemd: no such file or directory: unknown.
ERRO[0000] error waiting for container: context canceled 

I noticed that the docker image vyos was based on bullseye-slim.
I can not find /lib/systemd/systemd in bullseye-slim neither.

docker run -v /lib/modules:/lib/modules --privileged --name vyos_inside_docker -it debian:bullseye-slim
root@90dec9ebc269:/# 
root@90dec9ebc269:/# 
root@90dec9ebc269:/# ps -aef | grep systemd
bash: ps: command not found
root@90dec9ebc269:/# 
root@90dec9ebc269:/# ls -l /lib/systemd/systemd
ls: cannot access '/lib/systemd/systemd': No such file or directory
root@90dec9ebc269:/# 
root@90dec9ebc269:/# exit

How can I fix this?

  1. Edit Dockerfile change FROM ?
  2. Edit Dockerfile and vyos_install_stage_0x.sh add /lib/systemd/systemd to image?

I’am newbee to docker build…

Can you give me any suggestion?
Thanks.

Hi @ackema , I think it would be better to edit “FROM” line and remove “-slim” in your case, can you check that and confirm? Also, add the “/sbin/init” at the end of docker command when starting container.

Thank you very much!

Yestoday, I have tried following ways:

  1. modified Dockerfile
    change FROM debian:${DEBIAN_VERSION}-slim to debian:${DEBIAN_VERSION}


It didn’t work

  1. modified vyos_install_state_01.sh
    apt-get install systemd


It could be executed.
However, there was no vyos-1x, nginx, etc…

  1. modified vyos_install_state_01.sh
    apt-get install systemd
    apt-get install vyos-1x


It didn’t work. There was still no vyos-1x


I noticed the size of docker images was only about 200M, and the sizeof vyos iso was about 500MB.
There must be a lot of applications that I need to install, so I changed my mind.

-------- finnally, I worked out by this way:

  1. mount iso
  2. unsquash the rootfs
  3. tar rootfs | docker import
    and it works.

------ Still I have two questions:

  1. Is there a full docker-vyos image I can set(FROM) in Dockerfile? Which contain all the applications of vyos? Or what I should modify to build a complete vyos docker image?
  2. Docker container’s network support bridge(veth), host, macvlan and some other types. None of these type was an ethernet. When I use “set interfaces ethernet ethx address dhcp and commit”, It fails. Is there any way that can make the docker container support ethernet network?

Thanks a lot!

I would like to recommend you checking the following information:

Docker hub images - Docker Hub

Building and using VyOS for containerlab example -
https://docs.google.com/document/u/1/d/1TUUVGLzetAX7_BIO6qtKDCC89j40eHa7bZrGiM5a3j8/mobilebasic