Docker Ubuntu 컨테이너에 패키지를 설치하는 방법은 무엇입니까?

Docker Ubuntu 컨테이너에 패키지를 설치하는 방법은 무엇입니까?

기본적으로 다운로드되는 Ubuntu Docker 이미지를 사용합니다. 나는 원해요해당 컨테이너에서 네트워크 인터페이스와 IP 주소를 찾습니다., 그래서 포함된 패키지를 설치하고 싶은데 ifconfig왜 실패합니까? 감사해요.

$ sudo docker run  ubuntu apt update

WARNING: apt does not have a stable CLI interface. Use with caution in scripts.

Get:1 http://security.ubuntu.com/ubuntu bionic-security InRelease [88.7 kB]
Get:2 http://security.ubuntu.com/ubuntu bionic-security/universe amd64 Packages [160 kB]
Get:3 http://archive.ubuntu.com/ubuntu bionic InRelease [242 kB]
Get:4 http://security.ubuntu.com/ubuntu bionic-security/restricted amd64 Packages [5436 B]
Get:5 http://security.ubuntu.com/ubuntu bionic-security/main amd64 Packages [361 kB]
Get:6 http://archive.ubuntu.com/ubuntu bionic-updates InRelease [88.7 kB]
Get:7 http://security.ubuntu.com/ubuntu bionic-security/multiverse amd64 Packages [3910 B]
Get:8 http://archive.ubuntu.com/ubuntu bionic-backports InRelease [74.6 kB]
Get:9 http://archive.ubuntu.com/ubuntu bionic/main amd64 Packages [1344 kB]
Get:10 http://archive.ubuntu.com/ubuntu bionic/multiverse amd64 Packages [186 kB]
Get:11 http://archive.ubuntu.com/ubuntu bionic/universe amd64 Packages [11.3 MB]    
Get:12 http://archive.ubuntu.com/ubuntu bionic/restricted amd64 Packages [13.5 kB]
Get:13 http://archive.ubuntu.com/ubuntu bionic-updates/restricted amd64 Packages [10.8 kB]
Get:14 http://archive.ubuntu.com/ubuntu bionic-updates/universe amd64 Packages [955 kB]
Get:15 http://archive.ubuntu.com/ubuntu bionic-updates/main amd64 Packages [725 kB]
Get:16 http://archive.ubuntu.com/ubuntu bionic-updates/multiverse amd64 Packages [6968 B]
Get:17 http://archive.ubuntu.com/ubuntu bionic-backports/universe amd64 Packages [3659 B]
Get:18 http://archive.ubuntu.com/ubuntu bionic-backports/main amd64 Packages [942 B]
Fetched 15.6 MB in 27s (571 kB/s)
Reading package lists...
Building dependency tree...
Reading state information...
5 packages can be upgraded. Run 'apt list --upgradable' to see them.

그리고

$ sudo docker run  ubuntu apt upgrade

WARNING: apt does not have a stable CLI interface. Use with caution in scripts.

Reading package lists...
Building dependency tree...
Reading state information...
Calculating upgrade...
0 upgraded, 0 newly installed, 0 to remove and 0 not upgraded.

그리고

$ sudo docker run -it ubuntu  apt install net-tools
Reading package lists... Done
Building dependency tree       
Reading state information... Done
E: Unable to locate package net-tools

답변1

docker run이 명령은 별도의 컨테이너를 실행하므로 명령의 효과가 다음 컨테이너에 지속되지 않습니다 docker run.

새 컨테이너에서 프로세스를 실행합니다. docker run자체 파일 시스템, 자체 네트워크 및 자체 독립 프로세스 트리를 사용하여 프로세스를 시작합니다.

모든 명령을 결합해야 합니다.

docker run -it ubuntu /bin/sh -c 'apt update && apt upgrade -y && apt install -y net-tools'

여기에서 실행하려는 명령을 추가하세요 net-tools.

하나 를 쓸 가치 가 있을 수도 있습니다 Dockerfile.

관련 정보