Docker開發篇 | 01-Docker安裝最新版本ubuntu並啟動容器

Neutionwei發表於2020-10-08

一、拉取最新ubuntu映象

$ docker pull ubuntu:latest
latest: Pulling from library/ubuntu
d72e567cc804: Pull complete 
0f3630e5ff08: Pull complete 
b6a83d81d1f4: Pull complete 
Digest: sha256:bc2f7250f69267c9c6b66d7b6a81a54d3878bb85f1ebb5f951c896d13e6ba537
Status: Downloaded newer image for ubuntu:latest
docker.io/library/ubuntu:latest

二、生成ubuntu容器並退出

$ docker container run -p 8000:3000 -it ubuntu:latest /bin/bash 
root@bc7c3ac008b2:/# exit

 三、檢視ubuntu容器資訊

$ docker ps -a
CONTAINER ID        IMAGE               COMMAND             CREATED             STATUS                             PORTS                    NAMES         
bc7c3ac008b2        ubuntu:latest       "/bin/bash"         28 seconds ago      Exited (0) 13 seconds ago          0.0.0.0:8000->3000/tcp   zealous_einstein

 四、更改ubuntu容器為特定名字

$ docker rename bc7c3ac008b2 ubuntu-latest-buildroot
$ docker ps -a
CONTAINER ID        IMAGE               COMMAND             CREATED             STATUS                            PORTS                    NAMES     
bc7c3ac008b2        ubuntu:latest       "/bin/bash"         2 minutes ago       Exited (0) 2 minutes ago          0.0.0.0:8000->3000/tcp   ubuntu-latest-buildroot

注意:名字可以隨便命名,此處博主是用於編譯buildroot使用的。 


 五、啟動並進入ubuntu容器

$ docker container start ubuntu-latest-buildroot 
ubuntu-latest-buildroot
$ docker container exec -it ubuntu-latest-buildroot /bin/bash

 六、檢視ubuntu容器版本

root@bc7c3ac008b2:/# cat /etc/issue
Ubuntu 20.04.1 LTS \n \l

 七、更新apt源

root@bc7c3ac008b2:/# apt update     
Get:1 http://security.ubuntu.com/ubuntu focal-security InRelease [107 kB]                    
Get:2 http://archive.ubuntu.com/ubuntu focal InRelease [265 kB]                              
Get:3 http://archive.ubuntu.com/ubuntu focal-updates InRelease [111 kB]               
Get:4 http://security.ubuntu.com/ubuntu focal-security/main amd64 Packages [367 kB]
Get:5 http://archive.ubuntu.com/ubuntu focal-backports InRelease [98.3 kB]
Get:6 http://security.ubuntu.com/ubuntu focal-security/restricted amd64 Packages [75.9 kB]
Get:7 http://security.ubuntu.com/ubuntu focal-security/universe amd64 Packages [112 kB]
Get:8 http://security.ubuntu.com/ubuntu focal-security/multiverse amd64 Packages [1169 B]
Get:9 http://archive.ubuntu.com/ubuntu focal/main amd64 Packages [1275 kB] 
Get:10 http://archive.ubuntu.com/ubuntu focal/universe amd64 Packages [11.3 MB]              
Get:11 http://archive.ubuntu.com/ubuntu focal/restricted amd64 Packages [33.4 kB]            
Get:12 http://archive.ubuntu.com/ubuntu focal/multiverse amd64 Packages [177 kB]             
Get:13 http://archive.ubuntu.com/ubuntu focal-updates/universe amd64 Packages [303 kB]       
Get:14 http://archive.ubuntu.com/ubuntu focal-updates/multiverse amd64 Packages [21.6 kB]    
Get:15 http://archive.ubuntu.com/ubuntu focal-updates/main amd64 Packages [703 kB]           
Get:16 http://archive.ubuntu.com/ubuntu focal-updates/restricted amd64 Packages [88.7 kB]    
Get:17 http://archive.ubuntu.com/ubuntu focal-backports/universe amd64 Packages [4277 B]     
Fetched 15.1 MB in 29s (527 kB/s)                                                            
Reading package lists... Done
Building dependency tree       
Reading state information... Done
All packages are up to date.

八、安裝常用命令

$ apt install byobu vim-gtk inetutils-ping net-tools wget cpio unzip rsync

 九、安裝sudo命令並新增普通使用者

$ apt install sudo
$ adduser neutionwei

 十、把普通使用者新增到sudo

$ visido

 新增如下內容:

neutionwei	ALL=(ALL:ALL) ALL

十一、切換到普通使用者

$ su neutionwei

相關文章