Ubuntu Server 安装 Docker & Portainer 可视化面板 与 Code-Server

1,994 阅读3分钟
  1. 适用于国外云服务器
  2. 或适用于在“绕过局域网和中国大陆”科学上网环境下的虚拟机
  • 避免访问不到官方软件源

图片.png

图片.png

docs.docker.com/engine/inst…

图片.png

docs.docker.com/engine/inst…

图片.png

sudo apt-get remove docker docker-engine docker.io containerd runc

输出:

qwe@qweserv:~$ sudo apt-get remove docker docker-engine docker.io containerd runc
[sudo] password for qwe:
Reading package lists... Done
Building dependency tree... Done
Reading state information... Done
E: Unable to locate package docker-engine

图片.png

sudo apt-get update

输出

qwe@qweserv:~$ sudo apt-get update
Hit:1 http://cn.archive.ubuntu.com/ubuntu impish InRelease
Get:2 http://cn.archive.ubuntu.com/ubuntu impish-updates InRelease [110 kB]
Get:3 http://cn.archive.ubuntu.com/ubuntu impish-backports InRelease [101 kB]
Get:4 http://cn.archive.ubuntu.com/ubuntu impish-security InRelease [110 kB]
Get:5 http://cn.archive.ubuntu.com/ubuntu impish-updates/main amd64 Packages [285 kB]
Get:6 http://cn.archive.ubuntu.com/ubuntu impish-updates/main amd64 c-n-f Metadata [4,832 B]
Get:7 http://cn.archive.ubuntu.com/ubuntu impish-updates/universe amd64 Packages [101 kB]
Get:8 http://cn.archive.ubuntu.com/ubuntu impish-security/main amd64 Packages [199 kB]
Get:9 http://cn.archive.ubuntu.com/ubuntu impish-security/main amd64 c-n-f Metadata [3,396 B]
Get:10 http://cn.archive.ubuntu.com/ubuntu impish-security/universe amd64 Packages [58.9 kB]
Fetched 974 kB in 6s (158 kB/s)
Reading package lists... Done

sudo apt-get install \
    ca-certificates \
    curl \
    gnupg \
    lsb-release

输出

qwe@qweserv:~$ sudo apt-get install \
    ca-certificates \
    curl \
    gnupg \
    lsb-release
Reading package lists... Done
Building dependency tree... Done
Reading state information... Done
ca-certificates is already the newest version (20210119ubuntu1).
ca-certificates set to manually installed.
curl is already the newest version (7.74.0-1.3ubuntu2).
curl set to manually installed.
gnupg is already the newest version (2.2.20-1ubuntu4).
gnupg set to manually installed.
lsb-release is already the newest version (11.1.0ubuntu3).
lsb-release set to manually installed.
0 upgraded, 0 newly installed, 0 to remove and 18 not upgraded.
curl -fsSL https://download.docker.com/linux/ubuntu/gpg | sudo gpg --dearmor -o /usr/share/keyrings/docker-archive-keyring.gpg

上面命令无输出。

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

上面命令无输出。

sudo apt-get update

输出

qwe@qweserv:~$ sudo apt-get update
Hit:1 http://cn.archive.ubuntu.com/ubuntu impish InRelease
Get:2 https://download.docker.com/linux/ubuntu impish InRelease [48.9 kB]
Hit:3 http://cn.archive.ubuntu.com/ubuntu impish-updates InRelease
Get:4 https://download.docker.com/linux/ubuntu impish/stable amd64 Packages [4,136 B]
Hit:5 http://cn.archive.ubuntu.com/ubuntu impish-backports InRelease
Hit:6 http://cn.archive.ubuntu.com/ubuntu impish-security InRelease
Fetched 53.0 kB in 2s (34.9 kB/s)
Reading package lists... Done
sudo apt-get install docker-ce docker-ce-cli containerd.io

输出

qwe@qweserv:~$ sudo apt-get install docker-ce docker-ce-cli containerd.io
Reading package lists... Done
Building dependency tree... Done
Reading state information... Done
The following additional packages will be installed:
  docker-ce-rootless-extras docker-scan-plugin libltdl7 libslirp0 pigz
  slirp4netns
Suggested packages:
  aufs-tools cgroupfs-mount | cgroup-lite
The following NEW packages will be installed:
  containerd.io docker-ce docker-ce-cli docker-ce-rootless-extras
  docker-scan-plugin libltdl7 libslirp0 pigz slirp4netns
0 upgraded, 9 newly installed, 0 to remove and 18 not upgraded.
Need to get 97.2 MB of archives.
After this operation, 409 MB of additional disk space will be used.
Do you want to continue? [Y/n]

这里按下回车,表示"Y"

Get:1 https://download.docker.com/linux/ubuntu impish/stable amd64 containerd.io amd64 1.4.12-1 [23.7 MB]
Get:2 http://cn.archive.ubuntu.com/ubuntu impish/universe amd64 pigz amd64 2.6-1 [63.6 kB]
Get:3 http://cn.archive.ubuntu.com/ubuntu impish/main amd64 libltdl7 amd64 2.4.6-15 [38.8 kB]
Get:4 http://cn.archive.ubuntu.com/ubuntu impish-updates/main amd64 libslirp0 amd64 4.4.0-1ubuntu0.21.10.1 [58.2 kB]
Get:5 http://cn.archive.ubuntu.com/ubuntu impish/universe amd64 slirp4netns amd64 1.0.1-2 [28.2 kB]
Get:6 https://download.docker.com/linux/ubuntu impish/stable amd64 docker-ce-cli amd64 5:20.10.12~3-0~ubuntu-impish [40.7 MB]
Get:7 https://download.docker.com/linux/ubuntu impish/stable amd64 docker-ce amd64 5:20.10.12~3-0~ubuntu-impish [21.2 MB]
Get:8 https://download.docker.com/linux/ubuntu impish/stable amd64 docker-ce-rootless-extras amd64 5:20.10.12~3-0~ubuntu-impish [7,920 kB]
Get:9 https://download.docker.com/linux/ubuntu impish/stable amd64 docker-scan-plugin amd64 0.12.0~ubuntu-impish [3,517 kB]
Fetched 97.2 MB in 28s (3,434 kB/s)
Selecting previously unselected package pigz.
(Reading database ... 71029 files and directories currently installed.)
Preparing to unpack .../0-pigz_2.6-1_amd64.deb ...
Unpacking pigz (2.6-1) ...
Selecting previously unselected package containerd.io.
Preparing to unpack .../1-containerd.io_1.4.12-1_amd64.deb ...
Unpacking containerd.io (1.4.12-1) ...
Selecting previously unselected package docker-ce-cli.
Preparing to unpack .../2-docker-ce-cli_5%3a20.10.12~3-0~ubuntu-impish_amd64.deb ...
Unpacking docker-ce-cli (5:20.10.12~3-0~ubuntu-impish) ...
Selecting previously unselected package docker-ce.
Preparing to unpack .../3-docker-ce_5%3a20.10.12~3-0~ubuntu-impish_amd64.deb ...
Unpacking docker-ce (5:20.10.12~3-0~ubuntu-impish) ...
Selecting previously unselected package docker-ce-rootless-extras.
Preparing to unpack .../4-docker-ce-rootless-extras_5%3a20.10.12~3-0~ubuntu-impish_amd64.deb ...
Unpacking docker-ce-rootless-extras (5:20.10.12~3-0~ubuntu-impish) ...
Selecting previously unselected package docker-scan-plugin.
Preparing to unpack .../5-docker-scan-plugin_0.12.0~ubuntu-impish_amd64.deb ...
Unpacking docker-scan-plugin (0.12.0~ubuntu-impish) ...
Selecting previously unselected package libltdl7:amd64.
Preparing to unpack .../6-libltdl7_2.4.6-15_amd64.deb ...
Unpacking libltdl7:amd64 (2.4.6-15) ...
Selecting previously unselected package libslirp0:amd64.
Preparing to unpack .../7-libslirp0_4.4.0-1ubuntu0.21.10.1_amd64.deb ...
Unpacking libslirp0:amd64 (4.4.0-1ubuntu0.21.10.1) ...
Selecting previously unselected package slirp4netns.
Preparing to unpack .../8-slirp4netns_1.0.1-2_amd64.deb ...
Unpacking slirp4netns (1.0.1-2) ...
Setting up docker-scan-plugin (0.12.0~ubuntu-impish) ...
Setting up containerd.io (1.4.12-1) ...
Created symlink /etc/systemd/system/multi-user.target.wants/containerd.service → /lib/systemd/system/containerd.service.
Setting up libltdl7:amd64 (2.4.6-15) ...
Setting up docker-ce-cli (5:20.10.12~3-0~ubuntu-impish) ...
Setting up libslirp0:amd64 (4.4.0-1ubuntu0.21.10.1) ...
Setting up pigz (2.6-1) ...
Setting up docker-ce-rootless-extras (5:20.10.12~3-0~ubuntu-impish) ...
Setting up slirp4netns (1.0.1-2) ...
Setting up docker-ce (5:20.10.12~3-0~ubuntu-impish) ...
Created symlink /etc/systemd/system/multi-user.target.wants/docker.service → /lib/systemd/system/docker.service.
Created symlink /etc/systemd/system/sockets.target.wants/docker.socket → /lib/systemd/system/docker.socket.
Processing triggers for man-db (2.9.4-2) ...
Processing triggers for libc-bin (2.34-0ubuntu3) ...
Scanning processes...
Scanning linux images...

Running kernel seems to be up-to-date.

No services need to be restarted.

No containers need to be restarted.

No user sessions are running outdated binaries.

到这里,Docker就安装完成了。

现在我们开始安装Portainer。

docs.portainer.io/v/ce-2.11/s…

图片.png

在非root账户下会碰到无权限问题,所以命令前需要加上sudo。 如果机器上没有sudo命令,使用su root,然后apt install sudo -y安装一下就可以了。

qwe@qweserv:~$ docker volume create portainer_data
Got permission denied while trying to connect to the Docker daemon socket at unix:///var/run/docker.sock: Post "http://%2Fvar%2Frun%2Fdocker.sock/v1.24/volumes/create": dial unix /var/run/docker.sock: connect: permission denied
sudo docker volume create portainer_data

输出

qwe@qweserv:~$ sudo docker volume create portainer_data
portainer_data
sudo docker run -d -p 8000:8000 -p 9443:9443 --name portainer \
    --restart=always \
    -v /var/run/docker.sock:/var/run/docker.sock \
    -v portainer_data:/data \
    portainer/portainer-ce:2.11.1

输出

qwe@qweserv:~$ sudo docker run -d -p 8000:8000 -p 9443:9443 --name portainer \
    --restart=always \
    -v /var/run/docker.sock:/var/run/docker.sock \
    -v portainer_data:/data \
    portainer/portainer-ce:2.11.1
Unable to find image 'portainer/portainer-ce:2.11.1' locally
2.11.1: Pulling from portainer/portainer-ce
772227786281: Pull complete
96fd13befc87: Pull complete
b3238bddfe78: Pull complete
Digest: sha256:3ff080a0cd2a45bd0bde046069973b3fe642c3e4d43c5b429dd7b77f0057c7d7
Status: Downloaded newer image for portainer/portainer-ce:2.11.1
2a32a64ddb83408c163cc0343b84e1951678212c5083d08b821455bd0d8790bc

Portainer 命令部分已经结束了,我们离安装完成还差一点点,因为这个公网也能访问的,访问https://IP:9443,注意是https,http是进不去的,会出现一句话Client sent an HTTP request to an HTTPS server.

图片.png 图片.png 图片.png

这里我创建一个12345678的密码

图片.png

点击左上角的Home

图片.png

点击中间的local

图片.png

点击左侧栏或者右边的container

图片.png

点击按钮 Add Container 添加我们的 Code-Server 吧!

图片.png

图片.png

图片.png

图片.png

复制这个就可以啦

linuxserver/code-server

第一步回来粘贴

第二步打开随机端口

图片.png

最后按下 Deploy the container 就可以啦

图片.png

图片.png

右上角的提示表示已经成功,我们列表里多出来一项了

图片.png

我们需要 Code-Server 的密码来进入,所以我们点击 Console

图片.png

图片.png

图片.png 进入 /root/.config/code-server/ 目录

cd .config/code-server/

查看里面有什么文件

ls

看 config.yaml 的内容

cat config.yaml

输出

root@a7bdcd876d2c:~# cd .config/code-server/
root@a7bdcd876d2c:~/.config/code-server# ls
config.yaml
root@a7bdcd876d2c:~/.config/code-server# cat config.yaml 
bind-addr: 127.0.0.1:8080
auth: password
password: 0440feabd05d924362aa980c
cert: false
root@a7bdcd876d2c:~/.config/code-server#

随机出的密码是0440feabd05d924362aa980c,每个人都不一样

现在返回

图片.png

看浏览器左上角的机器IP,然后看右边的端口,49153是随机出来的,转发的,对外的开放端口,8443则是Code-Server的固定内部端口

图片.png

你需要访问http://IP:Port,我的情况,我就需要浏览器访问http://192.168.117.130:49153

图片.png

图片.png