无网络环境下安装docker容器

安装静态二进制文件

参考地址:https://docs.docker.com/install/linux/docker-ce/binaries/#install-static-binaries

下载静态二进制存档。转到 https://download.docker.com/linux/static/stable/ (或更改stablenightlytest),选择您的硬件平台,然后下载.tgz与您要安装的Docker Engine-Community版本有关的文件。

20191225111345.png

本文章下载为:docker-19.03.5.tgz 注意要跟据平台硬件下载以免造成不兼容

将下载好的文件上传到服务器


20191225111836.png

解压文件

tar xzvf docker-19.03.5.tgz 
20191225112103.png

将二进制文件移到可执行路径上的目录,例如/usr/bin/

sudo cp docker/* /usr/bin/

配置 docker.service文件

vi /usr/lib/systemd/system/docker.service
[Unit]
Description=Docker Application Container Engine
Documentation=https://docs.docker.com
After=network-online.target firewalld.service
Wants=network-online.target

[Service]
Type=notify
ExecStart=/usr/bin/dockerd
ExecReload=/bin/kill -s HUP $MAINPID
LimitNOFILE=infinity
LimitNPROC=infinity
TimeoutStartSec=0
Delegate=yes
KillMode=process
Restart=on-failure
StartLimitBurst=3
StartLimitInterval=60s

[Install]
WantedBy=multi-user.target

启动dockerd服务进程

systemctl daemon-reload
systemctl start docker.service

查看docker 安装信息

docker info

Client:
 Debug Mode: false

Server:
 Containers: 0
  Running: 0
  Paused: 0
  Stopped: 0
 Images: 0
 Server Version: 19.03.5
 Storage Driver: overlay2
  Backing Filesystem: xfs
  Supports d_type: true
  Native Overlay Diff: true
 Logging Driver: json-file
 Cgroup Driver: cgroupfs
 Plugins:
  Volume: local
  Network: bridge host ipvlan macvlan null overlay
  Log: awslogs fluentd gcplogs gelf journald json-file local logentries splunk syslog
 Swarm: inactive
 Runtimes: runc
 Default Runtime: runc
 Init Binary: docker-init
 containerd version: b34a5c8af56e510852c35414db4c1f4fa6172339
 runc version: 3e425f80a8c931f88e6d94a8c831b9d5aa481657
 init version: fec3683
 Security Options:
  seccomp
   Profile: default
 Kernel Version: 3.10.0-957.el7.x86_64
 Operating System: Red Hat Enterprise Linux Server 7.6 (Maipo)
 OSType: linux
 Architecture: x86_64
 CPUs: 1
 Total Memory: 1.795GiB
 Name: localhost.localdomain
 ID: AV7D:WG7N:CATA:5SOR:IDCS:OPLA:QXVN:5Z3E:P6BH:5YHL:3IMT:FGLP
 Docker Root Dir: /var/lib/docker
 Debug Mode: false
 Registry: https://index.docker.io/v1/
 Labels:
 Experimental: false
 Insecure Registries:
  127.0.0.0/8
 Live Restore Enabled: false
 Product License: Community Engine

开机自动启动

sudo systemctl enable docker

由于我们是在无网络状态下安装的docker 容器所以我们也需要下载相关的镜像进行试运行

使用有网服务器下载好镜像

[root@localhost ~]# docker images
REPOSITORY          TAG                 IMAGE ID            CREATED             SIZE
mysql               5.5                 d404d78aa797        7 months ago        205MB

保存

docker save  d404d78aa797  > mysql5.tar

查看保存的tar

[root@localhost ynxx]# ls
 mysql5.tar

将此镜像上传到所需安装的服务器中

导入镜像

mysql5.tar 为需导入的镜像

[root@localhost ynxx]# docker load < mysql5.tar 
6270adb5794c: Loading layer [==================================================>]  58.45MB/58.45MB
432b5f62e513: Loading layer [==================================================>]  338.4kB/338.4kB
647245c554e4: Loading layer [==================================================>]  10.44MB/10.44MB
ddc265b679cf: Loading layer [==================================================>]  4.472MB/4.472MB
af84b063c827: Loading layer [==================================================>]  1.536kB/1.536kB
f83622e85376: Loading layer [==================================================>]  41.54MB/41.54MB
4054cc666efd: Loading layer [==================================================>]  94.41MB/94.41MB
90b4ae8695b5: Loading layer [==================================================>]  3.584kB/3.584kB
a9c5a24e943f: Loading layer [==================================================>]  3.584kB/3.584kB
f49eaacc87a0: Loading layer [==================================================>]  9.728kB/9.728kB
c9f3545812c8: Loading layer [==================================================>]  1.536kB/1.536kB
Loaded image ID: sha256:d404d78aa797c87c255e5ae2beb5d8d0e4d095f930b1f20dc208eaa957477b74

查看导入的镜像

[root@localhost ynxx]# docker images
REPOSITORY          TAG                 IMAGE ID            CREATED             SIZE
<none>              <none>              d404d78aa797        7 months ago        205MB

重命名镜像

[root@localhost ynxx]# docker tag d404d78aa797 mysql:5.5
[root@localhost ynxx]# docker images #再次查看名称已更改
REPOSITORY          TAG                 IMAGE ID            CREATED             SIZE
mysql               5.5                 d404d78aa797        7 months ago        205MB

启动镜像

[root@localhost ynxx]# docker run -itd --name mysql-test -p 3306:3306 -e MYSQL_ROOT_PASSWORD=123456 mysql:5.5
8cd5768993ea2f21362504a034aff0e1543c99acc917a2da113600096619b934
[root@localhost ynxx]# docker ps
CONTAINER ID        IMAGE               COMMAND                  CREATED             STATUS              PORTS                    NAMES
8cd5768993ea        mysql:5.5           "docker-entrypoint.s…"   5 minutes ago       Up 5 minutes        0.0.0.0:3306->3306/tcp   mysql-test

进入容器中登录

[root@localhost ynxx]# docker exec -it 8cd5768993ea /bin/bash
root@8cd5768993ea:/# mysql -u root -p
Enter password: 
Welcome to the MySQL monitor.  Commands end with ; or \g.
Your MySQL connection id is 2
Server version: 5.5.62 MySQL Community Server (GPL)

Copyright (c) 2000, 2018, Oracle and/or its affiliates. All rights reserved.

Oracle is a registered trademark of Oracle Corporation and/or its
affiliates. Other names may be trademarks of their respective
owners.

Type 'help;' or '\h' for help. Type '\c' to clear the current input statement.

mysql> 

到此结束,在无网络的情况下,安装docker---->上传打包的镜像---> 运行镜像

注意:docker save与docker export的区别

参考地址:
https://blog.csdn.net/sun_qiangwei/article/details/80766800

最后编辑于
©著作权归作者所有,转载或内容合作请联系作者
  • 序言:七十年代末,一起剥皮案震惊了整个滨河市,随后出现的几起案子,更是在滨河造成了极大的恐慌,老刑警刘岩,带你破解...
    沈念sama阅读 159,569评论 4 363
  • 序言:滨河连续发生了三起死亡事件,死亡现场离奇诡异,居然都是意外死亡,警方通过查阅死者的电脑和手机,发现死者居然都...
    沈念sama阅读 67,499评论 1 294
  • 文/潘晓璐 我一进店门,熙熙楼的掌柜王于贵愁眉苦脸地迎上来,“玉大人,你说我怎么就摊上这事。” “怎么了?”我有些...
    开封第一讲书人阅读 109,271评论 0 244
  • 文/不坏的土叔 我叫张陵,是天一观的道长。 经常有香客问我,道长,这世上最难降的妖魔是什么? 我笑而不...
    开封第一讲书人阅读 44,087评论 0 209
  • 正文 为了忘掉前任,我火速办了婚礼,结果婚礼上,老公的妹妹穿的比我还像新娘。我一直安慰自己,他们只是感情好,可当我...
    茶点故事阅读 52,474评论 3 287
  • 文/花漫 我一把揭开白布。 她就那样静静地躺着,像睡着了一般。 火红的嫁衣衬着肌肤如雪。 梳的纹丝不乱的头发上,一...
    开封第一讲书人阅读 40,670评论 1 222
  • 那天,我揣着相机与录音,去河边找鬼。 笑死,一个胖子当着我的面吹牛,可吹牛的内容都是我干的。 我是一名探鬼主播,决...
    沈念sama阅读 31,911评论 2 313
  • 文/苍兰香墨 我猛地睁开眼,长吁一口气:“原来是场噩梦啊……” “哼!你这毒妇竟也来了?” 一声冷哼从身侧响起,我...
    开封第一讲书人阅读 30,636评论 0 202
  • 序言:老挝万荣一对情侣失踪,失踪者是张志新(化名)和其女友刘颖,没想到半个月后,有当地人在树林里发现了一具尸体,经...
    沈念sama阅读 34,397评论 1 246
  • 正文 独居荒郊野岭守林人离奇死亡,尸身上长有42处带血的脓包…… 初始之章·张勋 以下内容为张勋视角 年9月15日...
    茶点故事阅读 30,607评论 2 246
  • 正文 我和宋清朗相恋三年,在试婚纱的时候发现自己被绿了。 大学时的朋友给我发了我未婚夫和他白月光在一起吃饭的照片。...
    茶点故事阅读 32,093评论 1 261
  • 序言:一个原本活蹦乱跳的男人离奇死亡,死状恐怖,灵堂内的尸体忽然破棺而出,到底是诈尸还是另有隐情,我是刑警宁泽,带...
    沈念sama阅读 28,418评论 2 254
  • 正文 年R本政府宣布,位于F岛的核电站,受9级特大地震影响,放射性物质发生泄漏。R本人自食恶果不足惜,却给世界环境...
    茶点故事阅读 33,074评论 3 237
  • 文/蒙蒙 一、第九天 我趴在偏房一处隐蔽的房顶上张望。 院中可真热闹,春花似锦、人声如沸。这庄子的主人今日做“春日...
    开封第一讲书人阅读 26,092评论 0 8
  • 文/苍兰香墨 我抬头看了看天上的太阳。三九已至,却和暖如春,着一层夹袄步出监牢的瞬间,已是汗流浃背。 一阵脚步声响...
    开封第一讲书人阅读 26,865评论 0 196
  • 我被黑心中介骗来泰国打工, 没想到刚下飞机就差点儿被人妖公主榨干…… 1. 我叫王不留,地道东北人。 一个月前我还...
    沈念sama阅读 35,726评论 2 276
  • 正文 我出身青楼,却偏偏与公主长得像,于是被迫代替她去往敌国和亲。 传闻我的和亲对象是个残疾皇子,可洞房花烛夜当晚...
    茶点故事阅读 35,627评论 2 270