#How to run a file to install dependencies when building a docker container?

100 messages · Page 1 of 1 (latest)

dusk shoal
#

Problem Statement

  1. I am trying to compile chromium from source code in a docker container.
  2. It requires installing some dependencies given in file install-build-deps.sh which is just a file that makes install-build-deps.py excutable.
  3. I tried RUN /chromium/src/build/install-build-deps.sh but I received:
------                                                                                                                                                        
 > [7/8] RUN /chromium/src/build/install-build-deps.sh:
0.500 /bin/sh: 1: /chromium/src/build/install-build-deps.sh: not found
  1. Asked ChatGPT and It said that the only way is to copy the entire chromium directory but this is not possible as it is too big and my root and home are separate and root does not contain enough space.
  2. The only way is just opening the container and running the script maunally. The problem with this is that it is not persistant (I need to call it each time).
  3. This is the script install-build-deps.sh: (file is also executable (I can run it If I run the container))
#!/bin/bash -e

# Copyright 2012 The Chromium Authors
# Use of this source code is governed by a BSD-style license that can be
# found in the LICENSE file.

exec "$(cd $(dirname $0) && pwd)/install-build-deps.py" "$@"
karmic jacinth
#

What does the Dockerfile look like?

#

You're trying to access /chromium/ but it's unlikely that that is the correct path

dusk shoal
#

Minute

#
# Use an official Ubuntu base image with Docker already installed
FROM ubuntu:20.04

# Set environment variables
ENV DEBIAN_FRONTEND=noninteractive

# Install curl (if not already installed)
RUN apt-get update && \
    apt-get install -y curl git lsb-release python3 sudo && \
    rm -rf /var/lib/apt/lists/*

# Install vim and git
RUN apt-get update && \
    apt-get install -y vim git && \
    rm -rf /var/lib/apt/lists/*

# Set the working directory to the existing Chromium source directory
WORKDIR /home/chromium_user/Desktop/GSoC/depot_tools

RUN git config --global --add safe.directory /depot_tools

# Set the working directory to the existing Chromium source directory
WORKDIR /chromium

# MOUNT the Chromium directory form the host
VOLUME /home/omar/Desktop/GSoC/chromium:/chromium

# Install Dependencies
WORKDIR /build
COPY /home/omar/Desktop/GSoC/chromium/src/build/ /build
RUN /build/install-build-deps.sh

# Expose any necessary ports (if needed)
EXPOSE 8080

# Start Chromium (modify this command as needed)
CMD ["echo", "Chromium build environment is ready. You can now build the project."]
#

Command to run it $ docker run --rm -it --name chrom-b -v ~/Desktop/GSoC/chromium:/chromium -v ~/Desktop/GSoC/depot_tools:/depot_tools -w /chromium chrom-b bash

karmic jacinth
#

You have chromium/src/build/install-build-deps.sh on your local machine, correct?

dusk shoal
karmic jacinth
#

Try mounting to a different place I guess

#

oh wait

#

COPY /home/omar/Desktop/GSoC/chromium/src/build/ /build

dusk shoal
karmic jacinth
#

I wonder if that extra slash after the first build is an issue

#

not sure, just a guess here

dusk shoal
#

No, that extra slash won't do anything (tried)

karmic jacinth
#

Actually, do we even need to copy the stuff if we have the directory mounted?

#

Couldn't you just RUN /chromium/src/build/install-build-deps.sh?

dusk shoal
karmic jacinth
#

Yeah but after mounting you do the RUN

dusk shoal
#

The docker works fine if I just run container and run from within it all these scripts. but this is not "persistent :("

karmic jacinth
#

You have the mount and then you do the run

dusk shoal
karmic jacinth
#

What prevents you from doing

VOLUME /home/omar/Desktop/GSoC/chromium:/chromium
RUN /chromium/src/build/install-build-deps.sh
#

But I also don't see the issue with your dockerfile

#

ah nvm

#

volume doesn't mount

#

sorry I'm st00pid

mystic wagon
#

is this the path you use to execute it manually?
/build/install-build-deps.sh

dusk shoal
#

Well... I think it half-worked:

$ docker build -t chrom-b .
.... (long log)
 => CACHED [6/8] WORKDIR /chromium                                                                                                                       0.0s
 => CACHED [7/8] WORKDIR /build                                                                                                                          0.0s
 => ERROR [8/8] RUN /build/install-build-deps.sh                                                                                                         0.5s
------                                                                                                                                                        
 > [8/8] RUN /build/install-build-deps.sh:
0.473 /bin/sh: 1: /build/install-build-deps.sh: not found
------
Dockerfile:31
--------------------
  29 |     WORKDIR /build
  30 |     VOLUME /home/omar/Desktop/GSoC/chromium/src/build:/build
  31 | >>> RUN /build/install-build-deps.sh
  32 |     
  33 |     # Expose any necessary ports (if needed)
--------------------
ERROR: failed to solve: process "/bin/sh -c /build/install-build-deps.sh" did not complete successfully: exit code: 127
dusk shoal
#

Sorry for missing your message 😦

mystic wagon
dusk shoal
# mystic wagon well use this path with RUN then

I do not know what is error 127 but I will check it out

 => CACHED [6/7] WORKDIR /chromium                                                                                                                       0.0s
 => ERROR [7/7] RUN /chromium/build/install-build-deps.sh                                                                                                0.3s
------                                                                                                                                                        
 > [7/7] RUN /chromium/build/install-build-deps.sh:
0.231 /bin/sh: 1: /chromium/build/install-build-deps.sh: not found
------
Dockerfile:31
--------------------
  29 |     #WORKDIR /build
  30 |     #VOLUME /home/omar/Desktop/GSoC/chromium/src/build:/build
  31 | >>> RUN /chromium/build/install-build-deps.sh
  32 |     #RUN /build/install-build-deps.sh
  33 |     
--------------------
ERROR: failed to solve: process "/bin/sh -c /chromium/build/install-build-deps.sh" did not complete successfully: exit code: 127
mystic wagon
#

[7/7] RUN /chromium/build/install-build-deps.sh:
0.231 /bin/sh: 1: /chromium/build/install-build-deps.sh: not found

#

same problem

dusk shoal
#

😦

mystic wagon
dusk shoal
#

One thing that I noticed is that the docker container does not get destroyed. You can persist image after running and modifying it. I am looking into this now as a workaround.

mystic wagon
#

an image has no lifetime
container data persists till the container gets deleted
container data can persist longer using volumes

dusk shoal
#

It turns out that this is possible. Check out this:

  1. docker ps: (to get id)
  2. docker commit 69cfcbf76d98 chrom-b:dpv1.0
  3. docker images (check if container available)
dusk shoal
mystic wagon
#

@dusk shoal
well I looked up volumes again and your people seem to be right - as I thought they would

volumes get created when the container starts
so they don't exist when building your docker image

therefore RUN can not work with volume data since RUN is part of the building process
so you need to copy the files before using RUN

CMD on the other hand is executed when the container starts
so using CMD you could work with volumes
but you want to have all necessary data in the image, so you need to use RUN

mystic wagon
dusk shoal
mystic wagon
#

remove the RUN command and just copy the files
build your image and run a container
check to which directory the files got copied to

dusk shoal
mystic wagon
# dusk shoal How to check such thing?

you access your container and search your file system with the console

or if you are using docker desktop, you can click on your container and go to the "Files" tab

#

there has to be some kind of build directory that should include the copied files

mystic wagon
dusk shoal
#

Without mounting, there are no files at all (neither in chromium nor in build)

#
$ docker run --rm -it --name chrom-b -v ~/Desktop/GSoC/depot_tools:/depot_tools -w /chromium/src chrom-b:dpv1.0 bash
root@62915c8f2ff9:/chromium/src# ls
root@62915c8f2ff9:/chromium/src# cd
root@62915c8f2ff9:~# ls
root@62915c8f2ff9:~# cd /
root@62915c8f2ff9:/# ls
bin   chromium     dev  home  lib32  libx32  mnt  proc  run   srv  tmp  var
boot  depot_tools  etc  lib   lib64  media   opt  root  sbin  sys  usr
root@62915c8f2ff9:/# cd chromium/
root@62915c8f2ff9:/chromium# ls
src
root@62915c8f2ff9:/chromium# cd src/
root@62915c8f2ff9:/chromium/src# ls
root@62915c8f2ff9:/chromium/src#
mystic wagon
dusk shoal
#
FROM ubuntu:20.04

# Set environment variables
ENV DEBIAN_FRONTEND=noninteractive

# Install curl (if not already installed)
RUN apt-get update && \
    apt-get install -y curl git lsb-release python3 sudo && \
    rm -rf /var/lib/apt/lists/*

# Install vim and git
RUN apt-get update && \
    apt-get install -y vim git && \
    rm -rf /var/lib/apt/lists/*

# Set the working directory to the existing Chromium source directory
WORKDIR /home/chromium_user/Desktop/GSoC/depot_tools

# Export depot_tools path
#ENV PATH="/depot_tools:{PATH}"
RUN git config --global --add safe.directory /depot_tools

# Set the working directory to the existing Chromium source directory
WORKDIR /chromium

# MOUNT the Chromium directory form the host
VOLUME /home/omar/Desktop/GSoC/chromium:/chromium

# Install Dependencies
#WORKDIR /build
#VOLUME /home/omar/Desktop/GSoC/chromium/src/build:/build
#RUN /build/install-build-deps.sh

# Expose any necessary ports (if needed)
EXPOSE 8080

# Start Chromium (modify this command as needed)
CMD ["echo", "Chromium build environment is ready. You can now build the project."]
mystic wagon
#

nothing happens here

# Install Dependencies
#WORKDIR /build
#VOLUME /home/omar/Desktop/GSoC/chromium/src/build:/build
#RUN /build/install-build-deps.sh

try this

WORKDIR .
COPY /home/omar/Desktop/GSoC/chromium/src/build/ /build
# RUN /build/install-build-deps.sh
dusk shoal
#
 => ERROR [7/7] COPY /home/omar/Desktop/GSoC/chromium/src/build /build                                                                                   0.0s
------
 > [7/7] COPY /home/omar/Desktop/GSoC/chromium/src/build /build:
------
Dockerfile:32
--------------------
  30 |     # Install Dependencies
  31 |     #WORKDIR /build
  32 | >>> COPY /home/omar/Desktop/GSoC/chromium/src/build /build
  33 |     #RUN /build/install-build-deps.sh
  34 |     
--------------------
ERROR: failed to solve: failed to compute cache key: failed to calculate checksum of ref 152d6a12-49ad-4c81-b8fd-38cc7c646912::jbhaqrsfnhpmbhg0e8bql1qne: failed to walk /var/lib/docker/tmp/buildkit-mount790282117/home/omar/Desktop/GSoC/chromium/src: lstat /var/lib/docker/tmp/buildkit-mount790282117/home/omar/Desktop/GSoC/chromium/src: no such file or directory
#

Minute

#

Same exact error as you see and the following is my docker

#
FROM ubuntu:20.04

# Set environment variables
ENV DEBIAN_FRONTEND=noninteractive

# Install curl (if not already installed)
RUN apt-get update && \
    apt-get install -y curl git lsb-release python3 sudo && \
    rm -rf /var/lib/apt/lists/*

# Install vim and git
RUN apt-get update && \
    apt-get install -y vim git && \
    rm -rf /var/lib/apt/lists/*

# Set the working directory to the existing Chromium source directory
WORKDIR /home/chromium_user/Desktop/GSoC/depot_tools

# Export depot_tools path
#ENV PATH="/depot_tools:{PATH}"
RUN git config --global --add safe.directory /depot_tools

# Set the working directory to the existing Chromium source directory
WORKDIR /chromium

# MOUNT the Chromium directory form the host
VOLUME /home/omar/Desktop/GSoC/chromium:/chromium

# Install Dependencies
WORKDIR .
COPY /home/omar/Desktop/GSoC/chromium/src/build /build
#RUN /build/install-build-deps.sh

# Expose any necessary ports (if needed)
EXPOSE 8080

# Start Chromium (modify this command as needed)
CMD ["echo", "Chromium build environment is ready. You can now build the project."]
mystic wagon
dusk shoal
#

Nope

mystic wagon
# dusk shoal

hmm
something seems off on your side

tried it myself

dusk shoal
#

IDK 😦

#

that is totally awkward. It really does not make any sense

#

let me double check

dusk shoal
mystic wagon
#

doesn't matter as long as your container keeps running

dusk shoal
#

after like an hour, I think the reason is that we are using a wrong path

#

when you build the docker, where do you stand? in tha parent of /resources?

mystic wagon
dusk shoal
#

XDDDDDDDDDDDDDDDD

#

If I told you the real reason, you would kill me XD

#

docker file is in /chromium

#

I should COPY /src...

#

XD

mystic wagon
dusk shoal
#

This is the current dockerfile:

# Use an official Ubuntu base image with Docker already installed
FROM ubuntu:20.04

# Set environment variables
ENV DEBIAN_FRONTEND=noninteractive

# Install curl (if not already installed)
RUN apt-get update && \
    apt-get install -y curl git lsb-release python3 sudo && \
    rm -rf /var/lib/apt/lists/*

# Install vim and git
RUN apt-get update && \
    apt-get install -y vim git && \
    rm -rf /var/lib/apt/lists/*

# Set the working directory to the existing Chromium source directory
#WORKDIR /home/chromium_user/Desktop/GSoC/depot_tools

# Export depot_tools path
#ENV PATH="/depot_tools:{PATH}"
RUN git config --global --add safe.directory /depot_tools

# Set the working directory to the existing Chromium source directory
#WORKDIR /chromium

# MOUNT the Chromium directory form the host
#VOLUME /home/omar/Desktop/GSoC/chromium:/chromium

# Install Dependencies
#WORKDIR /build
WORKDIR .
COPY /src/build /build
#RUN /build/install-build-deps.sh

# Expose any necessary ports (if needed)
EXPOSE 8080

# Start Chromium (modify this command as needed)
CMD ["echo", "Chromium build environment is ready. You can now build the project."]
#

This is how I called and what there is in the container:

$ docker build -t chrom-b .
.....
 => CACHED [2/6] RUN apt-get update &&     apt-get install -y curl git lsb-release python3 sudo &&     rm -rf /var/lib/apt/lists/*                                          0.0s
 => CACHED [3/6] RUN apt-get update &&     apt-get install -y vim git &&     rm -rf /var/lib/apt/lists/*                                                                    0.0s
 => CACHED [4/6] RUN git config --global --add safe.directory /depot_tools                                                                                                  0.0s
------
 > [internal] load build context:
------
ERROR: failed to solve: error from sender: open src/build/linux/debian_bullseye_amd64-sysroot/debian: permission denied
mystic wagon
#

you still need to use COPY if you want to add the dependencies to your image

dusk shoal
#

Sorry, forgot to give you the new one, will edit message now

#

Done

#

Jesus.... XD

#

It worked XDDDDDDDDD

#

finally

#

just sudo resolved all issues

mystic wagon
#

nice

dusk shoal
mystic wagon
dusk shoal
# mystic wagon keep learning

IDK where you at or how can I help you. but I am insisting on this project because chromium is part of a google and it will contribute pretty much into hiring you in google, which I am looking for, without an interview in some cases.

#

Let me know if you are interested in helping you out in such thing

#

The docker is running smoothly but one big issue remained. I cannot build in an interactive manner. The script asks me for input (choose country) This is impossible to do IMHO.

Just thought to let you know