Ubuntu安装docker

Ubuntu安装docker

环境准备:Ubuntu22.04
安装文档:https://docs.docker.com/engine/install/ubuntu/

1、卸载安装过的docker,如果没有安装可以不需要卸载

root@wenk:~# sudo apt-get remove docker docker-engine docker.io containerd runc
Reading package lists... Done
Building dependency tree... Done
Reading state information... Done
E: Unable to locate package docker-engine
root@wenk:~# 

2、更新Ubuntu系统的仓库资源

root@wenk:~# sudo apt-get update
Hit:1 https://mirrors.tuna.tsinghua.edu.cn/ubuntu jammy InRelease
Hit:2 https://mirrors.tuna.tsinghua.edu.cn/ubuntu jammy-updates InRelease
Hit:3 https://mirrors.tuna.tsinghua.edu.cn/ubuntu jammy-backports InRelease
Hit:4 https://mirrors.tuna.tsinghua.edu.cn/ubuntu jammy-security InRelease
Reading package lists... Done
root@wenk:~# 

3、安装需要的其他软件

root@wenk:~# sudo apt-get install \
    ca-certificates \
    curl \
    gnupg \
    lsb-release

4、添加docker官方的gpgkey

root@wenk:~# sudo mkdir -m 0755 -p /etc/apt/keyrings
root@wenk:~# curl -fsSL https://download.docker.com/linux/ubuntu/gpg | sudo gpg --dearmor -o /etc/apt/keyrings/docker.gpg

5、添加docker官方的仓库文件,这样才可以去下载docker软件

echo \
  "deb [arch=$(dpkg --print-architecture) signed-by=/etc/apt/keyrings/docker.gpg] https://download.docker.com/linux/ubuntu \
  $(lsb_release -cs) stable" | sudo tee /etc/apt/sources.list.d/docker.list > /dev/null

6、再次更新系统的仓库文件对应的源数据

root@wenk:~# sudo apt-get update
Hit:1 http://mirrors.aliyun.com/ubuntu jammy InRelease
Hit:2 http://mirrors.aliyun.com/ubuntu jammy-security InRelease                                          
Hit:3 http://mirrors.aliyun.com/ubuntu jammy-updates InRelease                                           
Hit:4 http://mirrors.aliyun.com/ubuntu jammy-proposed InRelease                                          
Hit:5 http://mirrors.aliyun.com/ubuntu jammy-backports InRelease                               
Get:6 https://download.docker.com/linux/ubuntu jammy InRelease [48.9 kB]
Hit:7 https://mirrors.tuna.tsinghua.edu.cn/ubuntu jammy InRelease
Hit:8 https://mirrors.tuna.tsinghua.edu.cn/ubuntu jammy-updates InRelease
Hit:9 https://mirrors.tuna.tsinghua.edu.cn/ubuntu jammy-backports InRelease
Hit:10 https://mirrors.tuna.tsinghua.edu.cn/ubuntu jammy-security InRelease
Get:11 https://download.docker.com/linux/ubuntu jammy/stable amd64 Packages [13.6 kB]
Fetched 62.5 kB in 2s (39.2 kB/s)      
Reading package lists... Done
root@wenk:~# 

7、安装docker软件

sudo apt-get install docker-ce docker-ce-cli containerd.io docker-buildx-plugin docker-compose-plugin

8、启动docker

root@wenk:~# service docker start

root@wenk:~# ps aux|grep docker
root       12261  0.0  3.5 1316740 71432 ?       Ssl  06:58   0:00 /usr/bin/dockerd -H fd:// --containerd=/run/containerd/containerd.sock
root       12569  0.0  0.1   6476  2364 pts/2    S+   07:03   0:00 grep --color=auto docker
root@wenk:~# 

9、设置开机启动

root@wenk:~# systemctl enable docker
Synchronizing state of docker.service with SysV service script with /lib/systemd/systemd-sysv-install.
Executing: /lib/systemd/systemd-sysv-install enable docker
root@wenk:~# 

10、查看docker容器进程和镜像

root@wenk:~# docker ps
CONTAINER ID   IMAGE     COMMAND   CREATED   STATUS    PORTS     NAMES
root@wenk:~# docker images
REPOSITORY   TAG       IMAGE ID   CREATED   SIZE
root@wenk:~# 

11、拉取nginx镜像文件

root@wenk:~# docker pull nginx
Using default tag: latest
latest: Pulling from library/nginx
bb263680fed1: Pull complete 
258f176fd226: Pull complete 
a0bc35e70773: Pull complete 
077b9569ff86: Pull complete 
3082a16f3b61: Pull complete 
7e9b29976cce: Pull complete 
Digest: sha256:6650513efd1d27c1f8a5351cbd33edf85cc7e0d9d0fcb4ffb23d8fa89b601ba8
Status: Downloaded newer image for nginx:latest
docker.io/library/nginx:latest
root@wenk:~# 

12、启动docker容器

root@wenk:~# docker run --name sc-nginx-1 -p 8080:80 -d --cpu-shares 10 --cpus 1 --cpuset-cpus 0 -m 10000000 nginx
875cb2b32b6641365505469cd6c996f04f88e9f089963e83cebd7a516e53eb2e
root@wenk:~# docker ps 
CONTAINER ID   IMAGE     COMMAND                  CREATED         STATUS         PORTS                                   NAMES
875cb2b32b66   nginx     "/docker-entrypoint.…"   8 seconds ago   Up 7 seconds   0.0.0.0:8080->80/tcp, :::8080->80/tcp   sc-nginx-1
root@wenk:~# 

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值