Docker容器

docker安装linux

本文主要是介绍docker安装linux,对大家解决编程问题具有一定的参考价值,需要的程序猿们随着小编来一起学习吧!

一、 安装docker

下载docker离线安装包

  下载地址

    链接:https://pan.baidu.com/s/1GLXoyQ9ZrFpiq-iAzqdg6A
    提取码:nf7s

1、解压

    tar -xvf docker-18.06.1-ce.tgz

  2、将解压出来的docker文件内容移动到 /usr/bin/ 目录下

    cp docker/* /usr/bin/

  3、将docker注册为service

    vim /etc/systemd/system/docker.service

  4.将下列配置加到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
# the default is not to use systemd for cgroups because the delegate issues still
# exists and systemd currently does not support the cgroup feature set required
# for containers run by docker
# open 2375 port
ExecStart=/usr/bin/dockerd
ExecReload=/bin/kill -s HUP $MAINPID
# Having non-zero Limit*s causes performance problems due to accounting overhead
# in the kernel. We recommend using cgroups to do container-local accounting.
LimitNOFILE=infinity
LimitNPROC=infinity
LimitCORE=infinity
# Uncomment TasksMax if your systemd version supports it.
# Only systemd 226 and above support this version.
#TasksMax=infinity
TimeoutStartSec=0
# set delegate yes so that systemd does not reset the cgroups of docker containers
Delegate=yes
# kill only the docker process, not all processes in the cgroup
KillMode=process
# restart the docker process if it exits prematurely
Restart=onfailure
StartLimitBurst=3
StartLimitInterval=60s
[Install]
WantedBy=multi-user.target
#------------------------------------------------------------------------

-------------------------------
5、启动

chmod +x /etc/systemd/system/docker.service #添加文件权限并启动docker

systemctl daemon-reload #重载unit配置文件

systemctl enable docker.service # 生成自启动服务

systemctl start docker
docker -v
二、 安装docker-compose

  2.1 下载 docker-compose

    下载地址

    链接:https://pan.baidu.com/s/1MMob-u3jsR5OK8u4r1uZDA

    提取码:2336

  2.2 安装

    1. cd /usr/local/bin

    2. mv docker-compose-Linux-x86_64 docker-compose

    3. sudo chmod +x docker-compose
docker-compose -v

systemctl status firewalld.service
systemctl stop firewalld.service
systemctl disable firewalld.service

三 ,Harbor 安装
tar -zxvf harbor-offline-installer-v1.10.2.tgz

修改 vim /home/tools/harbor/harbor.yml
--------------------------------------------------
# Configuration file of Harbor

# The IP address or hostname to access admin UI and registry service.
# DO NOT use localhost or 127.0.0.1, because Harbor needs to be accessed by external clients.
# 本机IP端口
hostname: 192.168.1.201

# http related config
http:
# port for http, default is 80. If https enabled, this port will redirect to https port
port: 9877

# https related config
# 去掉https
#https:
# https port for harbor, default is 443
#port: 443
# The path of cert and key files for nginx
#certificate: /your/certificate/path
#private_key: /your/private/key/path

# Uncomment external_url if you want to enable external proxy
# And when it enabled the hostname will no longer used
# external_url: https://reg.mydomain.com:8433

# The initial password of Harbor admin
# It only works in first time to install harbor
# Remember Change the admin password from UI after launching Harbor.
harbor_admin_password: 12345

# Harbor DB configuration
database:
# The password for the root user of Harbor DB. Change this before any production use.
password: root123
# The maximum number of connections in the idle connection pool. If it <=0, no idle connections are retained.
max_idle_conns: 50
# The maximum number of open connections to the database. If it <= 0, then there is no limit on the number of open connections.
# Note: the default number of connections is 100 for postgres.
max_open_conns: 100

# The default data volume
# 修改加载目录
data_volume: /home

# Harbor Storage settings by default is using /data dir on local filesystem
# Uncomment storage_service setting If you want to using external storage
# storage_service:
# # ca_bundle is the path to the custom root ca certificate, which will be injected into the truststore
# # of registry's and chart repository's containers. This is usually needed when the user hosts a internal storage with self signed certificate.
# ca_bundle:

# # storage backend, default is filesystem, options include filesystem, azure, gcs, s3, swift and oss
# # for more info about this configuration please refer https://docs.docker.com/registry/configuration/
# filesystem:
# maxthreads: 100
# # set disable to true when you want to disable registry redirect
# redirect:
# disabled: false

# Clair configuration
clair:
# The interval of clair updaters, the unit is hour, set to 0 to disable the updaters.
updaters_interval: 12

jobservice:
# Maximum number of job workers in job service
max_job_workers: 10

notification:
# Maximum retry count for webhook job
webhook_job_max_retry: 10

chart:
# Change the value of absolute_url to enabled can enable absolute url in chart
absolute_url: disabled

# Log configurations
log:
# options are debug, info, warning, error, fatal
level: info
# configs for logs in local storage
local:
# Log files are rotated log_rotate_count times before being removed. If count is 0, old versions are removed rather than rotated.
rotate_count: 50
# Log files are rotated only if they grow bigger than log_rotate_size bytes. If size is followed by k, the size is assumed to be in kilobytes.
# If the M is used, the size is in megabytes, and if G is used, the size is in gigabytes. So size 100, size 100k, size 100M and size 100G
# are all valid.
rotate_size: 200M
# The directory on your host that store log
location: /var/log/harbor

# Uncomment following lines to enable external syslog endpoint.
# external_endpoint:
# # protocol used to transmit log to external endpoint, options is tcp or udp
# protocol: tcp
# # The host of external endpoint
# host: localhost
# # Port of external endpoint
# port: 5140

#This attribute is for migrator to detect the version of the .cfg file, DO NOT MODIFY!
_version: 1.10.0

# Uncomment external_database if using external database.
# external_database:
# harbor:
# host: harbor_db_host
# port: harbor_db_port
# db_name: harbor_db_name
# username: harbor_db_username
# password: harbor_db_password
# ssl_mode: disable
# max_idle_conns: 2
# max_open_conns: 0
# clair:
# host: clair_db_host
# port: clair_db_port
# db_name: clair_db_name
# username: clair_db_username
# password: clair_db_password
# ssl_mode: disable
# notary_signer:
# host: notary_signer_db_host
# port: notary_signer_db_port
# db_name: notary_signer_db_name
# username: notary_signer_db_username
# password: notary_signer_db_password
# ssl_mode: disable
# notary_server:
# host: notary_server_db_host
# port: notary_server_db_port
# db_name: notary_server_db_name
# username: notary_server_db_username
# password: notary_server_db_password
# ssl_mode: disable

# Uncomment external_redis if using external Redis server
# external_redis:
# host: redis
# port: 6379
# password:
# # db_index 0 is for core, it's unchangeable
# registry_db_index: 1
# jobservice_db_index: 2
# chartmuseum_db_index: 3
# clair_db_index: 4

# Uncomment uaa for trusting the certificate of uaa instance that is hosted via self-signed cert.
# uaa:
# ca_file: /path/to/ca

# Global proxy
# Config http proxy for components, e.g. http://my.proxy.com:3128
# Components doesn't need to connect to each others via http proxy.
# Remove component from `components` array if want disable proxy
# for it. If you want use proxy for replication, MUST enable proxy
# for core and jobservice, and set `http_proxy` and `https_proxy`.
# Add domain to the `no_proxy` field, when you want disable proxy
# for some special registry.
proxy:
http_proxy:
https_proxy:
# no_proxy endpoints will appended to 127.0.0.1,localhost,.local,.internal,log,db,redis,nginx,core,portal,postgresql,jobservice,registry,registryctl,clair,chartmuseum,notary-server
no_proxy:
components:
- core
- jobservice
- clair
--------------------------------------------------
安装
cd /home/tools/harbor/
./install.sh
管理端访问
http://192.168.1.201:9877/
账号:admin 密码:12345

6、开启2375,并配置http连接
---------------------
6.1开启2375 端口
vim /etc/docker/daemon.json
-------------------------------------
{
"registry-mirrors": ["https://docker.mirrors.ustc.edu.cn","http://hub-mirror.c.163.com","https://dockerhub.mirrors.nwafu.edu.cn"],
"insecure-registries":["192.168.1.201:9877"],
"max-concurrent-downloads": 10,
"log-driver": "json-file",
"log-level": "warn",
"log-opts": {
"max-size": "10m",
"max-file": "3"
},
"data-root": "/var/lib/docker",
"hosts": ["tcp://0.0.0.0:2375", "unix:///var/run/docker.sock"]
}
----------------------------------
systemctl daemon-reload
systemctl restart docker

docker rmi $(docker images | grep "none" | awk '{print $3}') 删除none 镜像


6.2docker客户端配置
vim /etc/docker/daemon.json
-------------------------------
{
"registry-mirrors": ["https://docker.mirrors.ustc.edu.cn","http://hub-mirror.c.163.com","https://dockerhub.mirrors.nwafu.edu.cn"],
"insecure-registries":["192.168.88.128:9877","192.168.1.201:9877"]
}
------------------------------------
客户端 docker login 192.168.1.201:9877
账号 admin
密码 12345
------------------------------配置成功
WARNING! Your password will be stored unencrypted in /root/.docker/config.json.
Configure a credential helper to remove this warning. See
https://docs.docker.com/engine/reference/commandline/login/#credentials-store

Login Succeeded
------------------------------------
7,推送基础镜像

镜像先打标签
docker tag centos_jdk8:v1.0.0 192.168.1.201:9877/base_java/centos_jdk8:v1.0.0

推送到仓库
docker push 192.168.1.201:9877/base_java/centos_jdk8:v1.0.0

拉取仓库镜像
docker pull 192.168.1.201:9877/base_java/centos_jdk8:v1.0.0


列出所有容器 ID
1
docker ps -aq
停止所有容器
1
docker stop $(docker ps -aq)
停止单个容器
1
docker stop 要停止的容器名
删除所有容器
1
docker rm $(docker ps -aq)
docker rmi -f $(docker images -q)
删除单个容器
1
docker rm 要删除的容器名
删除所有的镜像
1
docker rmi -f $(docker images 192.168.1.201:9877/xxl-job-admin/xxl-job-admin -q)
docker rmi -f $(docker images 192.168.1.201:9877/achilles-pts-b/achilles-pts-b -q)
docker run --name mynginx -d nginx:latest
离线安装的 docker 清理

# 本文只针对于通过解压安装包的方式进行docker的清理和卸载
# 停止docker服务
sudo systemctl stop docker

# 杀死docker进程(为防止特殊情况下有残留的docker进程)
ps -ef | grep docker | awk '{print $2}' | xargs sudo kill -s 9

# 删除持久化Docker状态的根目录
# 通过docker info |grep 'Docker Root Dir:'命令查看
# 默认值/var/lib/docker,可通过dockerd命令的--data-root选项修改
sudo rm -rf /home/ubuntu/data/docker

# 删除执行状态文件的根目录
# 默认值/var/run/docker,可通过dockerd命令的--exec-root选项修改
sudo rm -rf /var/run/docker
# 删除默认监听的Unix域套接字,容器中的进程可以通过它与Docker守护进程进行通信
sudo rm -rf /var/run/docker.sock
# 删除docker守护进程PID文件
# 默认值/var/run/docker.pid,可通过dockerd命令的-p或--pidfile选项修改
sudo rm -rf /var/run/docker.pid

# 删除系统服务配置文件
sudo rm -rf /etc/systemd/system/docker.service
# 删除docker配置文件
# 默认值/etc/docker/daemon.json,可通过dockerd命令的--config-file选项修改
sudo rm -rf /etc/docker/daemon.json
# 删除自动生成的文件,tls相关配置:~/.docker/{ca.pem,cert.pem,key.pem}
sudo rm -rf ~/.docker/

# 清理可执行文件
ls ~/tools/docker/install-package |awk '{print "/usr/local/bin/"$1}'|xargs sudo rm -rf
参考资料


docker 导出

docker save 192.168.1.201:9877/achilles-cloud-eim/achilles-cloud-eim-redis -o achilles-cloud-eim-redis.tar
docker load
压缩 gzip –c achilles-dfs.tar > achilles-dfs.tar.gz 解压 gunzip –c filename.gz > filename
docker load -i achilles-cloud-eim-mysql.tar

这篇关于docker安装linux的文章就介绍到这儿,希望我们推荐的文章对大家有所帮助,也希望大家多多支持为之网!