black-parrot / black-parrot-sim

BSD 3-Clause "New" or "Revised" License
11 stars 7 forks source link

Updated docker-compose.yml to reflect new Ubuntu20.04 Dockerfile #19

Closed cknizek closed 2 months ago

cknizek commented 6 months ago

I updated ./black-parrot-sim/docker-compose.yml to reflect new Dockerfile.ubuntu20.04 filename. Filename mismatch caused docker-compose build failure. After changing the filename in the dockerfile field of docker-compose.yml, it now works.

I also updated the README for black-parrot-sim because the docker-composeinstructions as listed weren't working for me. I don't know if I was doing something wrong, but I listed the sequence of commands I used to successfully run docker-compose (if it's helpful).

Lastly, I changed the line in Dockerfile.ubuntu20.04 that grabs the UID/GID of the user into a different argument (--user-group) because the original would not work properly for me... (I might've been doing something wrong though).

This is my first pull request, so I apologize if this is a little wonky. I hope these changes help!

Let me know if you have any questions, Colin

dpetrisko commented 6 months ago

The rename change is good, thank you.

What was wrong with the current flow? Other than needing to use sudo. Passing the UID and GID as makefile variables should work fine and allows users to set them to specific values.

cknizek commented 6 months ago

When running sudo docker-compose build and the line in Dockerfile.ubuntu20.04 is: RUN useradd --no-log-init --uid $USER_ID --gid $GROUP_ID --shell /bin/bash --create-home build, I receive the following error:

~/os/black-parrot-sim/docker    docker_issue !1  sudo docker-compose build                        
[+] Building 1.0s (13/14)                                                                              docker:default
 => [bp internal] load build definition from Dockerfile.ubuntu20.04                                              0.0s
 => => transferring dockerfile: 1.78kB                                                                           0.0s
 => [bp internal] load metadata for docker.io/library/ubuntu:20.04                                               0.6s
 => [bp internal] load .dockerignore                                                                             0.0s
 => => transferring context: 2B                                                                                  0.0s
 => [bp  1/11] FROM docker.io/library/ubuntu:20.04@sha256:80ef4a44043dec4490506e6cc4289eeda2d106a70148b74b5ae91  0.0s
 => CACHED [bp  2/11] RUN apt-get update && apt-get install -y apt-utils tzdata git vim gettext-base uuid-dev d  0.0s
 => CACHED [bp  3/11] RUN apt-get install -y python-is-python3                                                   0.0s
 => CACHED [bp  4/11] RUN ln -nsf /usr/bin/tclsh8.6 /usr/bin/tclsh                                               0.0s
 => CACHED [bp  5/11] RUN wget -O - https://apt.kitware.com/keys/kitware-archive-latest.asc 2>/dev/null | gpg -  0.0s
 => CACHED [bp  6/11] RUN apt-add-repository "deb https://apt.kitware.com/ubuntu/ $(lsb_release -cs) main"       0.0s
 => CACHED [bp  7/11] RUN apt-get clean                                                                          0.0s
 => CACHED [bp  8/11] RUN pip install orderedmultidict                                                           0.0s
 => CACHED [bp  9/11] RUN getent group $GROUP_ID || groupadd --gid $GROUP_ID build                               0.0s
 => ERROR [bp 10/11] RUN useradd --no-log-init --uid $USER_ID --gid $GROUP_ID --shell /bin/bash --create-home b  0.3s
------                                                                                                                
 > [bp 10/11] RUN useradd --no-log-init --uid $USER_ID --gid $GROUP_ID --shell /bin/bash --create-home build:
0.290 useradd: invalid user ID '--gid'
------
failed to solve: process "/bin/sh -c useradd --no-log-init --uid $USER_ID --gid $GROUP_ID --shell /bin/bash --create-home build" did not complete successfully: exit code: 3

When I run docker-compose build without sudo, I receive the following error (I think this is normal behavior for Docker though, IIRC you need root access):

~/os/black-parrot-sim/docker docker-compose build 
permission denied while trying to connect to the Docker daemon socket at unix:///var/run/docker.sock: Get "http://%2Fvar%2Frun%2Fdocker.sock/_ping": dial unix /var/run/docker.sock: connect: permission denied
dpetrisko commented 6 months ago

Okay, so a couple things to check

Now, the other problem is that's wrong is that USER_ID is blank.

 RUN useradd --no-log-init --uid $USER_ID --gid $GROUP_ID --shell /bin/bash --create-home build:
0.290 useradd: invalid user ID '--gid'

This is set through the makefile, so if you use make -C docker it should work automatically. However, sudo will override the uid and gid as 0:0, which is likely not what you want, as that will make the volume inaccessible from the user profile.

In that new branch, I've also added USER_ID and GROUP_ID makefile variables so that you can set those as well. So in total you could do something like:

USER_ID=$(id -u) \
GROUP_ID=$(id -g) \
DOCKER="sudo docker" \
make -C docker docker-compose docker-run
cknizek commented 6 months ago

Oh ok, when I initially cloned the repo and tried to run the Makefile from the black-parrot-sim directory, I received the following error:

make -C docker docker-compose                                ✔ 
make: Entering directory '/run/media/nouveau/data/open_source/black-parrot-sim/docker'
cd /run/media/nouveau/data/open_source/black-parrot-sim/docker; \
docker-compose build --build-arg USER_ID=1000 --build-arg GROUP_ID=1001 black-parrot-sim
no such service: black-parrot-sim
make: *** [Makefile:13: docker-compose] Error 1
make: Leaving directory '/run/media/nouveau/data/open_source/black-parrot-sim/docker'

I then ran the sequence of commands:

`USER_ID=$(id -u) \
GROUP_ID=$(id -g) \
DOCKER="sudo docker" \
make -C docker docker-compose docker-run`

and received the following error:

make -C docker docker-compose                                ✔ 
make: Entering directory '/run/media/nouveau/data/open_source/black-parrot-sim/docker'
cd /run/media/nouveau/data/open_source/black-parrot-sim/docker; \
docker-compose build --build-arg USER_ID=1000 --build-arg GROUP_ID=1001 black-parrot-sim
no such service: black-parrot-sim
make: *** [Makefile:13: docker-compose] Error 1
make: Leaving directory '/run/media/nouveau/data/open_source/black-parrot-sim/docker'

I then switched to the compose-fix branch, added my user to the docker group, ran the sequence of commands:

USER_ID=$(id -u) \
GROUP_ID=$(id -g) \
DOCKER="sudo docker" \
make -C docker docker-compose docker-run

and was able to successfully run the Makefile! So I think the issue is resolved.

I'm not sure if I'm supposed to close this pull request or something, but the issue seems to be resolved and the Docker build executed successfully. Thanks for your help!

dpetrisko commented 6 months ago

Great! I'll integrate that branch and add you as a coauthor. Thanks for the report!

dpetrisko commented 2 months ago

Merged from branch, thanks for the report