Skip to content

Improve setup-container.sh for Ubuntu 24.04 based docker-sonic-mgmt#20761

Merged
StormLiangMS merged 1 commit intosonic-net:masterfrom
wangxin:improve-setup-container
Sep 23, 2025
Merged

Improve setup-container.sh for Ubuntu 24.04 based docker-sonic-mgmt#20761
StormLiangMS merged 1 commit intosonic-net:masterfrom
wangxin:improve-setup-container

Conversation

@wangxin
Copy link
Copy Markdown
Collaborator

@wangxin wangxin commented Sep 22, 2025

Description of PR

Summary:
Fixes # (issue)

Type of change

  • Bug fix
  • Testbed and Framework(new/improvement)
  • New Test case
    • Skipped for non-supported platforms
  • Test case improvement

Back port request

  • 202205
  • 202305
  • 202311
  • 202405
  • 202411
  • 202505

Approach

What is the motivation for this PR?

To support docker-sonic-mgmt based on Ubuntu 24.04, the setup-container.sh needs some minor improvements:

How did you do it?

  1. The Ubuntu 24.04 docker image as account "ubuntu" by default. Its uid could conflict with the user's uid. This change added code to best effort deleting this default "ubuntu" account.
  2. In old docker-sonic-mgmt, python3 is installed in virtual environment. In 2024, the docker-sonic-mgmt was updated to install python3 in global environment. It's no longer necessary to hack the virtual environment. This change adjusted the sequence of conditions for hacking venv, so that the code can fail faster to skip this step. In the future, this piece of code should can be deleted.

How did you verify/test it?

Use the updated script to setup sonic-mgmt container use both old and new docker-sonic-mgmt images.

Any platform specific information?

Supported testbed topology if it's a new test case?

Documentation

To support docker-sonic-mgmt based on Ubuntu 24.04, the setup-container.sh needs some minor improvements:

1. The Ubuntu 24.04 docker image as account "ubuntu" by default. Its uid could conflict with the user's uid. This change added code to best effort deleting this default "ubuntu" account.
2. In old docker-sonic-mgmt, python3 is installed in virtual environment. In 2024, the docker-sonic-mgmt was updated to install python3 in global environment. It's no longer necessary to hack the virtual environment. This change adjusted the sequence of conditions for hacking venv, so that the code can fail faster to skip this step. In the future, this piece of code should can be deleted.

Signed-off-by: Xin Wang <xiwang5@microsoft.com>
@mssonicbld
Copy link
Copy Markdown
Collaborator

/azp run

@azure-pipelines
Copy link
Copy Markdown

Azure Pipelines successfully started running 1 pipeline(s).

Copy link
Copy Markdown
Contributor

@wsycqyz wsycqyz left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM

Copy link
Copy Markdown
Collaborator

@StormLiangMS StormLiangMS left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM

@StormLiangMS StormLiangMS merged commit ef24f2b into sonic-net:master Sep 23, 2025
19 checks passed
vidyac86 pushed a commit to vidyac86/sonic-mgmt that referenced this pull request Oct 23, 2025
…onic-net#20761)

To support docker-sonic-mgmt based on Ubuntu 24.04, the setup-container.sh needs some minor improvements:

1. The Ubuntu 24.04 docker image as account "ubuntu" by default. Its uid could conflict with the user's uid. This change added code to best effort deleting this default "ubuntu" account.
2. In old docker-sonic-mgmt, python3 is installed in virtual environment. In 2024, the docker-sonic-mgmt was updated to install python3 in global environment. It's no longer necessary to hack the virtual environment. This change adjusted the sequence of conditions for hacking venv, so that the code can fail faster to skip this step. In the future, this piece of code should can be deleted.

Signed-off-by: Xin Wang <xiwang5@microsoft.com>
mssonicbld pushed a commit that referenced this pull request Nov 11, 2025
…20761)

To support docker-sonic-mgmt based on Ubuntu 24.04, the setup-container.sh needs some minor improvements:

1. The Ubuntu 24.04 docker image as account "ubuntu" by default. Its uid could conflict with the user's uid. This change added code to best effort deleting this default "ubuntu" account.
2. In old docker-sonic-mgmt, python3 is installed in virtual environment. In 2024, the docker-sonic-mgmt was updated to install python3 in global environment. It's no longer necessary to hack the virtual environment. This change adjusted the sequence of conditions for hacking venv, so that the code can fail faster to skip this step. In the future, this piece of code should can be deleted.

Signed-off-by: Xin Wang <xiwang5@microsoft.com>
mssonicbld pushed a commit that referenced this pull request Nov 11, 2025
…20761)

To support docker-sonic-mgmt based on Ubuntu 24.04, the setup-container.sh needs some minor improvements:

1. The Ubuntu 24.04 docker image as account "ubuntu" by default. Its uid could conflict with the user's uid. This change added code to best effort deleting this default "ubuntu" account.
2. In old docker-sonic-mgmt, python3 is installed in virtual environment. In 2024, the docker-sonic-mgmt was updated to install python3 in global environment. It's no longer necessary to hack the virtual environment. This change adjusted the sequence of conditions for hacking venv, so that the code can fail faster to skip this step. In the future, this piece of code should can be deleted.

Signed-off-by: Xin Wang <xiwang5@microsoft.com>
mssonicbld pushed a commit that referenced this pull request Nov 11, 2025
…20761)

To support docker-sonic-mgmt based on Ubuntu 24.04, the setup-container.sh needs some minor improvements:

1. The Ubuntu 24.04 docker image as account "ubuntu" by default. Its uid could conflict with the user's uid. This change added code to best effort deleting this default "ubuntu" account.
2. In old docker-sonic-mgmt, python3 is installed in virtual environment. In 2024, the docker-sonic-mgmt was updated to install python3 in global environment. It's no longer necessary to hack the virtual environment. This change adjusted the sequence of conditions for hacking venv, so that the code can fail faster to skip this step. In the future, this piece of code should can be deleted.

Signed-off-by: Xin Wang <xiwang5@microsoft.com>
wangxin pushed a commit that referenced this pull request Nov 19, 2025
…20761) (#21266)

To support docker-sonic-mgmt based on Ubuntu 24.04, the setup-container.sh needs some minor improvements:

1. The Ubuntu 24.04 docker image as account "ubuntu" by default. Its uid could conflict with the user's uid. This change added code to best effort deleting this default "ubuntu" account.
2. In old docker-sonic-mgmt, python3 is installed in virtual environment. In 2024, the docker-sonic-mgmt was updated to install python3 in global environment. It's no longer necessary to hack the virtual environment. This change adjusted the sequence of conditions for hacking venv, so that the code can fail faster to skip this step. In the future, this piece of code should can be deleted.

Signed-off-by: Xin Wang <xiwang5@microsoft.com>
mssonicbld pushed a commit that referenced this pull request Nov 19, 2025
…20761)

To support docker-sonic-mgmt based on Ubuntu 24.04, the setup-container.sh needs some minor improvements:

1. The Ubuntu 24.04 docker image as account "ubuntu" by default. Its uid could conflict with the user's uid. This change added code to best effort deleting this default "ubuntu" account.
2. In old docker-sonic-mgmt, python3 is installed in virtual environment. In 2024, the docker-sonic-mgmt was updated to install python3 in global environment. It's no longer necessary to hack the virtual environment. This change adjusted the sequence of conditions for hacking venv, so that the code can fail faster to skip this step. In the future, this piece of code should can be deleted.

Signed-off-by: Xin Wang <xiwang5@microsoft.com>
mssonicbld added a commit to mssonicbld/sonic-buildimage that referenced this pull request Dec 3, 2025
<!--
     Please make sure you've read and understood our contributing guidelines:
     https://github.com/Azure/SONiC/blob/gh-pages/CONTRIBUTING.md

     ** Make sure all your commits include a signature generated with `git commit -s` **

     If this is a bug fix, make sure your description includes "fixes #xxxx", or
     "closes #xxxx" or "resolves #xxxx"

     Please provide the following information:
-->

#### Why I did it
The base image Ubuntu 20.04 of docker-sonic-mgmt is end of support now. Need to upgrade the base image and the dependent packages to address potential vulnerability issues.

DO NOT MERGE until sonic-net/sonic-mgmt#21045 is merged and cherry-picked to all current active branches.

##### Work item tracking
- Microsoft ADO **(number only)**:

#### How I did it
* Upgraded base image of docker-sonic-mgmt to Ubuntu 24.04.
* Upgraded the build environment to bookworm.
* Removed the logic of building flag `LEGACY_SONIC_MGMT_DOCKER`. All the sonic-mgmt branches are using python3 now. It's not necessary to build docker-sonic-mgmt to support python2. And python2 is end of support too.
* Version of python packages are not pinned down. This change has pros and cons.
  * Pros: Keep the docker-sonic-mgmt up to date to avoid future big version leap which could be difficult to handle.
  * Cons: Community package upgrade could have issue and cause regression.
* Version of ansible is pinned to 11.10.0. It's because pytest-ansible does not support the latest ansible due to ansible/pytest-ansible#489
* Python packages are installed to /opt/venv by following the recommendation of Ubuntu 24.04.
* The dash-api package is reverted to install from source code. The dash-api debian package built in bookworm cannot be installed in Ubuntu 24.04 due to dependency issues.
* Default user "ubuntu" of Ubuntu 24.04 is removed from the image to avoid potential issues. For details, please refer to sonic-net/sonic-mgmt#20761. Skipped adding regular user. With this change, the image will only have root user. The `setup-container.sh` tool in the sonic-mgmt repository can add regular user. Recommend to use the `setup-container.sh` tool to create sonic-mgmt container.
* Improved the code for installing docker and azure-cli.
* Remove the build dependency of the `ptf` debian package. It's because the `ptf` package is installed by python pip.

#### How to verify it
After the upgrade, there are some compatibility issues. The compatibility issues are fixed in sonic-net/sonic-mgmt#21045.
I am using that PR to verify that all PR test scripts can pass by using the upgraded docker-sonic-mgmt.

The fix in sonic-net/sonic-mgmt#21045 is backward compatible. Backward compatibility is verified by PR testing of sonic-net/sonic-mgmt#20851

<!--
If PR needs to be backported, then the PR must be tested against the base branch and the earliest backport release branch and provide tested image version on these two branches. For example, if the PR is requested for master, 202211 and 202012, then the requester needs to provide test results on master and 202012.
-->

#### Which release branch to backport (provide reason below if selected)

<!--
- Note we only backport fixes to a release branch, *not* features!
- Please also provide a reason for the backporting below.
- e.g.
- [x] 202006
-->

- [ ] 202205
- [ ] 202211
- [ ] 202305
- [ ] 202311
- [ ] 202405
- [ ] 202411
- [ ] 202505

#### Tested branch (Please provide the tested image version)

<!--
- Please provide tested image version
- e.g.
- [x] 20201231.100
-->

- [ ] <!-- image version 1 -->
- [ ] <!-- image version 2 -->

#### Description for the changelog
<!--
Write a short (one line) summary that describes the changes in this
pull request for inclusion in the changelog:
-->

<!--
 Ensure to add label/tag for the feature raised. example - PR#2174 under sonic-utilities repo. where, Generic Config and Update feature has been labelled as GCU.
-->

#### Link to config_db schema for YANG module changes
<!--
Provide a link to config_db schema for the table for which YANG model
is defined
Link should point to correct section on https://github.com/Azure/sonic-buildimage/blob/master/src/sonic-yang-models/doc/Configuration.md
-->

#### A picture of a cute animal (not mandatory but encouraged)
opcoder0 pushed a commit to opcoder0/sonic-mgmt that referenced this pull request Dec 8, 2025
…onic-net#20761)

To support docker-sonic-mgmt based on Ubuntu 24.04, the setup-container.sh needs some minor improvements:

1. The Ubuntu 24.04 docker image as account "ubuntu" by default. Its uid could conflict with the user's uid. This change added code to best effort deleting this default "ubuntu" account.
2. In old docker-sonic-mgmt, python3 is installed in virtual environment. In 2024, the docker-sonic-mgmt was updated to install python3 in global environment. It's no longer necessary to hack the virtual environment. This change adjusted the sequence of conditions for hacking venv, so that the code can fail faster to skip this step. In the future, this piece of code should can be deleted.

Signed-off-by: Xin Wang <xiwang5@microsoft.com>
mssonicbld added a commit to sonic-net/sonic-buildimage that referenced this pull request Dec 14, 2025
<!--
 Please make sure you've read and understood our contributing guidelines:
 https://github.com/Azure/SONiC/blob/gh-pages/CONTRIBUTING.md

 failure_prs.log Make sure all your commits include a signature generated with `git commit -s` **

 If this is a bug fix, make sure your description includes "fixes #xxxx", or
 "closes #xxxx" or "resolves #xxxx"

 Please provide the following information:
-->

#### Why I did it
The base image Ubuntu 20.04 of docker-sonic-mgmt is end of support now. Need to upgrade the base image and the dependent packages to address potential vulnerability issues.

DO NOT MERGE until sonic-net/sonic-mgmt#21045 is merged and cherry-picked to all current active branches.

##### Work item tracking
- Microsoft ADO **(number only)**:

#### How I did it
* Upgraded base image of docker-sonic-mgmt to Ubuntu 24.04.
* Upgraded the build environment to bookworm.
* Removed the logic of building flag `LEGACY_SONIC_MGMT_DOCKER`. All the sonic-mgmt branches are using python3 now. It's not necessary to build docker-sonic-mgmt to support python2. And python2 is end of support too.
* Version of python packages are not pinned down. This change has pros and cons.
 failure_prs.log Pros: Keep the docker-sonic-mgmt up to date to avoid future big version leap which could be difficult to handle.
 failure_prs.log Cons: Community package upgrade could have issue and cause regression.
* Version of ansible is pinned to 11.10.0. It's because pytest-ansible does not support the latest ansible due to ansible/pytest-ansible#489
* Python packages are installed to /opt/venv by following the recommendation of Ubuntu 24.04.
* The dash-api package is reverted to install from source code. The dash-api debian package built in bookworm cannot be installed in Ubuntu 24.04 due to dependency issues.
* Default user "ubuntu" of Ubuntu 24.04 is removed from the image to avoid potential issues. For details, please refer to sonic-net/sonic-mgmt#20761. Skipped adding regular user. With this change, the image will only have root user. The `setup-container.sh` tool in the sonic-mgmt repository can add regular user. Recommend to use the `setup-container.sh` tool to create sonic-mgmt container.
* Improved the code for installing docker and azure-cli.
* Remove the build dependency of the `ptf` debian package. It's because the `ptf` package is installed by python pip.

#### How to verify it
After the upgrade, there are some compatibility issues. The compatibility issues are fixed in sonic-net/sonic-mgmt#21045.
I am using that PR to verify that all PR test scripts can pass by using the upgraded docker-sonic-mgmt.

The fix in sonic-net/sonic-mgmt#21045 is backward compatible. Backward compatibility is verified by PR testing of sonic-net/sonic-mgmt#20851

<!--
If PR needs to be backported, then the PR must be tested against the base branch and the earliest backport release branch and provide tested image version on these two branches. For example, if the PR is requested for master, 202211 and 202012, then the requester needs to provide test results on master and 202012.
-->

#### Which release branch to backport (provide reason below if selected)

<!--
- Note we only backport fixes to a release branch, *not* features!
- Please also provide a reason for the backporting below.
- e.g.
- [x] 202006
-->

- [ ] 202205
- [ ] 202211
- [ ] 202305
- [ ] 202311
- [ ] 202405
- [ ] 202411
- [ ] 202505

#### Tested branch (Please provide the tested image version)

<!--
- Please provide tested image version
- e.g.
- [x] 20201231.100
-->

- [ ] <!-- image version 1 -->
- [ ] <!-- image version 2 -->

#### Description for the changelog
<!--
Write a short (one line) summary that describes the changes in this
pull request for inclusion in the changelog:
-->

<!--
 Ensure to add label/tag for the feature raised. example - PR#2174 under sonic-utilities repo. where, Generic Config and Update feature has been labelled as GCU.
-->

#### Link to config_db schema for YANG module changes
<!--
Provide a link to config_db schema for the table for which YANG model
is defined
Link should point to correct section on https://github.com/Azure/sonic-buildimage/blob/master/src/sonic-yang-models/doc/Configuration.md
-->

#### A picture of a cute animal (not mandatory but encouraged)
gshemesh2 pushed a commit to gshemesh2/sonic-mgmt that referenced this pull request Dec 16, 2025
…onic-net#20761)

To support docker-sonic-mgmt based on Ubuntu 24.04, the setup-container.sh needs some minor improvements:

1. The Ubuntu 24.04 docker image as account "ubuntu" by default. Its uid could conflict with the user's uid. This change added code to best effort deleting this default "ubuntu" account.
2. In old docker-sonic-mgmt, python3 is installed in virtual environment. In 2024, the docker-sonic-mgmt was updated to install python3 in global environment. It's no longer necessary to hack the virtual environment. This change adjusted the sequence of conditions for hacking venv, so that the code can fail faster to skip this step. In the future, this piece of code should can be deleted.

Signed-off-by: Xin Wang <xiwang5@microsoft.com>
Signed-off-by: Guy Shemesh <gshemesh@nvidia.com>
AharonMalkin pushed a commit to AharonMalkin/sonic-mgmt that referenced this pull request Dec 16, 2025
…onic-net#20761)

To support docker-sonic-mgmt based on Ubuntu 24.04, the setup-container.sh needs some minor improvements:

1. The Ubuntu 24.04 docker image as account "ubuntu" by default. Its uid could conflict with the user's uid. This change added code to best effort deleting this default "ubuntu" account.
2. In old docker-sonic-mgmt, python3 is installed in virtual environment. In 2024, the docker-sonic-mgmt was updated to install python3 in global environment. It's no longer necessary to hack the virtual environment. This change adjusted the sequence of conditions for hacking venv, so that the code can fail faster to skip this step. In the future, this piece of code should can be deleted.

Signed-off-by: Xin Wang <xiwang5@microsoft.com>
Signed-off-by: Aharon Malkin <amalkin@nvidia.com>
gshemesh2 pushed a commit to gshemesh2/sonic-mgmt that referenced this pull request Dec 21, 2025
…onic-net#20761)

To support docker-sonic-mgmt based on Ubuntu 24.04, the setup-container.sh needs some minor improvements:

1. The Ubuntu 24.04 docker image as account "ubuntu" by default. Its uid could conflict with the user's uid. This change added code to best effort deleting this default "ubuntu" account.
2. In old docker-sonic-mgmt, python3 is installed in virtual environment. In 2024, the docker-sonic-mgmt was updated to install python3 in global environment. It's no longer necessary to hack the virtual environment. This change adjusted the sequence of conditions for hacking venv, so that the code can fail faster to skip this step. In the future, this piece of code should can be deleted.

Signed-off-by: Xin Wang <xiwang5@microsoft.com>
Signed-off-by: Guy Shemesh <gshemesh@nvidia.com>
venu-nexthop pushed a commit to venu-nexthop/sonic-mgmt that referenced this pull request Jan 13, 2026
…onic-net#20761)

To support docker-sonic-mgmt based on Ubuntu 24.04, the setup-container.sh needs some minor improvements:

1. The Ubuntu 24.04 docker image as account "ubuntu" by default. Its uid could conflict with the user's uid. This change added code to best effort deleting this default "ubuntu" account.
2. In old docker-sonic-mgmt, python3 is installed in virtual environment. In 2024, the docker-sonic-mgmt was updated to install python3 in global environment. It's no longer necessary to hack the virtual environment. This change adjusted the sequence of conditions for hacking venv, so that the code can fail faster to skip this step. In the future, this piece of code should can be deleted.

Signed-off-by: Xin Wang <xiwang5@microsoft.com>
yifan-nexthop pushed a commit to nexthop-ai/sonic-mgmt that referenced this pull request Jan 14, 2026
…onic-net#20761)

To support docker-sonic-mgmt based on Ubuntu 24.04, the setup-container.sh needs some minor improvements:

1. The Ubuntu 24.04 docker image as account "ubuntu" by default. Its uid could conflict with the user's uid. This change added code to best effort deleting this default "ubuntu" account.
2. In old docker-sonic-mgmt, python3 is installed in virtual environment. In 2024, the docker-sonic-mgmt was updated to install python3 in global environment. It's no longer necessary to hack the virtual environment. This change adjusted the sequence of conditions for hacking venv, so that the code can fail faster to skip this step. In the future, this piece of code should can be deleted.

Signed-off-by: Xin Wang <xiwang5@microsoft.com>
Signed-off-by: YiFan Wang <yifan@nexthop.ai>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment