docker || 基本知识和部署(centos7)

docker 是什么?

docker是一个软件,使用go语言开发,作用是对容器进行管理。

docker是容器技术的经典代表,docker 容器启动软件,颠覆了我们传统的软件安装的方式。

使用容器的好处

1.成本低廉
2.管理方便

容器和虚拟机的区别?

docker的优势:

1.启动速度快

2.资源消耗小

3.扩展方便

docker的缺点:

1. app隔离没有虚拟机彻底

2. 虚拟机的安全性要高一些

3. 层次不一样:虚拟机多一层封装

docker底层是如何做隔离的?

name space;kernel lxc;control groups;lxc+namespace+cgroups

Docker Engine 使用了以下 Linux 的隔离技术:

The pid namespace: 管理 PID 命名空间 (PID: Process ID)

The network namespace: 管理网络命名空间(NET: Networking)

The ipc namespace: 管理进程间通信命名空间(IPC: InterProcess Communication)

The mount namespace: 管理文件系统挂载点命名空间 (MNT: Mount)

The uts namespace: Unix 时间系统隔离. (UTS: Unix Timesharing System)

The user namespace:管理用户命令空间

namespace有什么作用?

1.隔离资源

2.是内存里存放数据的一个空间

关闭防火墙对docker的影响?

关闭防火墙或者清除防火墙规则,会导致iptables里的docker相关SNAT或者DNAT等策略失效,导致容器不能和外面的机器通信。
重启docker服务,会自动添加docker相关的iptables规则。


docker在centos7系统的安装过程:

1.卸载原来安装过的docker,如果没有安装可以不需要卸载。

yum remove docker \
                  docker-client \
                  docker-client-latest \
                  docker-common \
                  docker-latest \
                  docker-latest-logrotate \
                  docker-logrotate \
                  docker-engine

#The Docker Engine package is now called docker-ce.

2.安装yum相关的工具,下载docker-ce.repo文件

yum install -y yum-utils

yum-config-manager \
>     --add-repo \
>     https://download.docker.com/linux/centos/docker-ce.repo

添加docker官方的yum仓库文件,一会需要去docker官方的yum仓库下载软件。

如果下载比较慢的话,可以自己更改下载源。

[root@sc-docker yum.repos.d]# cd /etc/yum.repos.d/   # 存放所有的yum仓库文件的

[root@sc-docker yum.repos.d]# ls
CentOS-Base.repo  CentOS-Debuginfo.repo  CentOS-Media.repo    CentOS-Vault.repo          docker-ce.repo
CentOS-CR.repo    CentOS-fasttrack.repo  CentOS-Sources.repo  CentOS-x86_64-kernel.repo  nginx.repo
docker-ce.repo  # 就是我们刚刚下载的

3.安装docker-ce软件

yum install docker-ce docker-ce-cli containerd.io docker-compose-plugin -y


# container engine 容器引擎
# docker是一个容器管理的软件
# docker-ce 是服务器端软件 server
# docker-ce-cli 是客户端软件 client
# docker-compose-plugin 是compose插件,用来批量启动很多容器,在单台机器上
# containerd.io  底层用来启动容器的

4.启动docker,并且设置docker开机启动

[root@sc-docker yum.repos.d]# systemctl start docker
[root@sc-docker yum.repos.d]# systemctl enable docker
Created symlink /etc/systemd/system/multi-user.target.wants/docker.service → /usr/lib/systemd/system/docker.service.

[root@sc-docker yum.repos.d]# ps aux|grep docker
root       16210  0.4  2.0 1368904 79400 ?       Ssl  17:29   0:00 /usr/bin/dockerd-H fd:// --containerd=/run/containerd/containerd.sock
root       16363  0.0  0.0  12348  1112 pts/0    S+   17:30   0:00 grep --color=auto docker

docker的一个容器,背后就是一个进程。

5.测试运行一个docker容器,下载nginx镜像并且启动一个nignx的服务。

[root@sc-docker yum.repos.d]# docker pull  nginx  # 下载nginx的镜像
Using default tag: latest
latest: Pulling from library/nginx
7a6db449b51b: Pull complete 
ca1981974b58: Pull complete 
d4019c921e20: Pull complete 
7cb804d746d4: Pull complete 
e7a561826262: Pull complete 
7247f6e5c182: Pull complete 
Digest: sha256:b95a99feebf7797479e0c5eb5ec0bdfa5d9f504bc94da550c2f58e839ea6914f
Status: Downloaded newer image for nginx:latest
docker.io/library/nginx:latest

[root@sc-docker yum.repos.d]# docker images   # 查看已经下载的镜像
REPOSITORY   TAG       IMAGE ID       CREATED      SIZE
nginx        latest    2b7d6430f78d   2 days ago   142MB


# 使用docker启动一个容器,可以理解为开启一台虚拟机
[root@sc-docker yum.repos.d]# docker run -d -p 8090:80 --name  sc-nginx  nginx
bda1e5c73838b5e48e711f27f3473f1749006786c28e061a9469f49e93439e32

# docker run 是启动容器的命令
# -d 在后台运行 daemon 守护进程

# -p 8090:80  指定端口映射    DNAT 访问本机的8090端口,转发到docker容器的80端口

# --name  sc-nginx  指定容器的名字
#  nginx 是镜像的名字

# 在windows浏览器上测试能否访问宿主机的8090端口
# http://192.168.1.183:8090/

使用容器启动一个MySQL的服务:

1.下载镜像

[root@sc-docker ~]# docker pull mysql:5.7.39
5.7.39: Pulling from library/mysql
9815334b7810: Pull complete 
f85cb6fccbfd: Pull complete 
b63612353671: Pull complete 
447901201612: Pull complete 
9b6bc806cc29: Pull complete 
24ec1f4b3b0d: Pull complete 
207ed1eb2fd4: Pull complete 
27cbde3edd97: Pull complete 
0a5aa35cc154: Pull complete 
e6c92bf6471b: Pull complete 
07b80de0d1af: Pull complete 
Digest: sha256:c1bda6ecdbc63d3b0d3a3a3ce195de3dd755c4a0658ed782a16a0682216b9a48
Status: Downloaded newer image for mysql:5.7.39
docker.io/library/mysql:5.7.39

2.启动容器

[root@sc-docker ~]# docker run -d --name sc-mysql-1 -p 3306:3306 -e MYSQL_ROOT_PASSWORD="sc123456
3d15dbc364ac4ed187ceb68c1a2215c33b6512680864cc49a31bf799052b277c

[root@sc-docker ~]# docker ps
CONTAINER ID   IMAGE     COMMAND  CREATED   STATUS     PORTS    NAMES
3d15dbc364ac   mysql:5.7.39   "docker-entrypoint.s…"   3 seconds ago   Up 3 seconds   0.0.0.0:330cp, 33060/tcp   sc-mysql-1
73e618b7f293   nginx          "/docker-entrypoint.…"   3 hours ago     Up 3 hours     0.0.0.0:809                sc-nginx

3.进入mysql容器里

docker exec 进入容器内容,执行命令 execute
-it 开启一个终端,交互式登陆进入
sc-mysql-1  容器的名字
 bash 进入容器里运行的程序 

[root@sc-docker ~]# docker exec -it sc-mysql-1 bash
bash-4.2# ls
bin   dev              entrypoint.sh  home  lib64  mnt  proc  run   srv  tmp  var
boot  docker-entrypoint-initdb.d  etc         lib   media  opt  root  sbin  sys  usr

bash-4.2# cat /etc/re
redhat-release  resolv.conf    
 
bash-4.2# cat /etc/redhat-release 
Red Hat Enterprise Linux Server release 7.9 (Maipo)

bash-4.2# mysql -uroot -p"sc123456"
mysql: [Warning] Using a password on the command line interface can be insecure.
Welcome to the MySQL monitor.  Commands end with ; or \g.
Your MySQL connection id is 3
Server version: 5.7.39 MySQL Community Server (GPL)

Copyright (c) 2000, 2022, Oracle and/or its affiliates.

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> show databases;
+--------------------+
| Database           |
+--------------------+
| information_schema |
| mysql              |
| performance_schema |
| sys                |
+--------------------+
4 rows in set (0.00 sec)

mysql> exit
Bye
bash-4.2# exit
exit
[root@sc-docker ~]# 

# 启动失败的排错过程
[root@sc-docker yum.repos.d]# docker logs a5b752cc4485  # 查看容器启动失败的日志
2022-08-25 07:05:50+00:00 [Note] [Entrypoint]: Entrypoint script for MySQL Server 5.7.39-1.el7 started.
2022-08-25 07:05:50+00:00 [Note] [Entrypoint]: Switching to dedicated user 'mysql'
2022-08-25 07:05:50+00:00 [Note] [Entrypoint]: Entrypoint script for MySQL Server 5.7.39-1.el7 started.
2022-08-25 07:05:50+00:00 [ERROR] [Entrypoint]: Database is uninitialized and password option is not specified
    You need to specify one of the following:
    - MYSQL_ROOT_PASSWORD
    - MYSQL_ALLOW_EMPTY_PASSWORD
    - MYSQL_RANDOM_ROOT_PASSWORD

[root@sc-docker yum.repos.d]# docker logs sc-mysql-1
2022-08-25 07:05:50+00:00 [Note] [Entrypoint]: Entrypoint script for MySQL Server 5.7.39-1.el7 started.
2022-08-25 07:05:50+00:00 [Note] [Entrypoint]: Switching to dedicated user 'mysql'
2022-08-25 07:05:50+00:00 [Note] [Entrypoint]: Entrypoint script for MySQL Server 5.7.39-1.el7 started.
2022-08-25 07:05:50+00:00 [ERROR] [Entrypoint]: Database is uninitialized and password option is not specified
    You need to specify one of the following:
    - MYSQL_ROOT_PASSWORD
    - MYSQL_ALLOW_EMPTY_PASSWORD
    - MYSQL_RANDOM_ROOT_PASSWORD

# docker rmi nginx 删除镜像

[root@sc-docker yum.repos.d]# docker ps -a
CONTAINER ID   IMAGE          COMMAND                  CREATED         STATUS                     PORTS                                   NAMES
a5b752cc4485   mysql:5.7.39   "docker-entrypoint.s…"   6 minutes ago   Exited (1) 6 minutes ago                                           sc-mysql-1
bda1e5c73838   nginx          "/docker-entrypoint.…"   3 hours ago     Up 3 hours                 0.0.0.0:8090->80/tcp, :::8090->80/tcp   sc-nginx

[root@sc-docker  yum.repos.d]# docker rm sc-mysql-1  # 删除启动失败的容器,正在运行的容器不能直接删除 sc-mysql-1

docker常用命令


docker images # 查看已经下载的镜像
docker search # 查找镜像
docker rmi    # 删除镜像
docker pull   # 拉取镜像
docker save   # 导出镜像
docker load   # 导入镜像;

docker run = docker create + docker start  # 启动容器
docker stop   # 停止容器 
docker rm     # 删除容器
docker restart # 重启容器
docker ps     # 查看容器状态
docker ps -a  # 查看所有的容器进程
docker inspect # 查看详细信息
docker logs  # 查看日志

docker network ls # 查看网络类型
docker top        # 查看docker运行的进程信息
docker version    # 查看版本
docker stat       # 显示容器使用的系统资源
docker volume     # 查看卷

docker  --help 查看docker 帮助文档

[root@sc-docker ~]# docker --help

  attach      Attach local standard input, output, and error streams to a running container
  build       Build an image from a Dockerfile
  commit      Create a new image from a container's changes
  cp          Copy files/folders between a container and the local filesystem
  create      Create a new container
  diff        Inspect changes to files or directories on a container's filesystem
  events      Get real time events from the server
  exec        Run a command in a running container
  export      Export a container's filesystem as a tar archive
  history     Show the history of an image
  images      List images
  import      Import the contents from a tarball to create a filesystem image
  info        Display system-wide information
  inspect     Return low-level information on Docker objects
  kill        Kill one or more running containers
  load        Load an image from a tar archive or STDIN
  login       Log in to a Docker registry
  logout      Log out from a Docker registry
  logs        Fetch the logs of a container
  pause       Pause all processes within one or more containers
  port        List port mappings or a specific mapping for the container
  ps          List containers
  pull        Pull an image or a repository from a registry
  push        Push an image or a repository to a registry
  rename      Rename a container
  restart     Restart one or more containers
  rm          Remove one or more containers
  rmi         Remove one or more images
  run         Run a command in a new container
  save        Save one or more images to a tar archive (streamed to STDOUT by default)
  search      Search the Docker Hub for images
  start       Start one or more stopped containers
  stats       Display a live stream of container(s) resource usage statistics
  stop        Stop one or more running containers
  tag         Create a tag TARGET_IMAGE that refers to SOURCE_IMAGE
  top         Display the running processes of a container
  unpause     Unpause all processes within one or more containers
  update      Update configuration of one or more containers
  version     Show the Docker version information
  wait        Block until one or more containers stop, then print their exit codes

  • 1
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 打赏
    打赏
  • 0
    评论
### 回答1: 安装Jumpserver的方法如下: 1. 在CentOS 7上安装DockerDocker Compose; 2. 下载Jumpserver的Docker-compose配置文件,并按照说明进行修改; 3. 运行Docker-compose命令启动Jumpserver服务; 4. 访问Jumpserver的Web页面并进行配置。 需要注意的是,安装Jumpserver需要一定的Linux和Docker的基础知识,不熟悉的话建议先学习相关知识再进行安装。 ### 回答2: Jumpserver是一款基于Web的开源堡垒机系统,可以实现对服务器、云主机、网络设备等网络资产的统一管理和访问控制,帮助企业构建起更加安全、高效的运维管理平台。本文将介绍Jumpserver在CentOS7上的安装和部署过程。 1、安装依赖项 在CentOS7的终端中执行以下命令以安装Jumpserver所需的依赖项: yum install epel-release -y yum install yum-utils -y yum-config-manager --add-repo https://mirrors.aliyun.com/docker-ce/linux/centos/docker-ce.repo yum makecache fast yum install docker-ce docker-ce-cli containerd.io -y systemctl start docker systemctl enable docker 2、下载Jumpserver 在安装Jumpserver之前,需要从https://github.com/jumpserver/jumpserver/releases 页面中获取最新版本的Jumpserver程序包,并将其下载到CentOS7服务器上。最新的Jumpserver版本目前为1.6.1。 3、安装Jumpserver 在CentOS7服务器上创建一个新的目录以存储Jumpserver程序包,然后将其解压缩到该目录中。 mkdir -p /opt/jumpserver cd /opt/jumpserver mv /path/to/jumpserver-1.6.1.tar.gz . tar zxvf jumpserver-1.6.1.tar.gz 修改 Jumpserver 主目录的所属和权限: chown -R 1000:1000 /opt/jumpserver/jumpserver chmod -R +x /opt/jumpserver/jumpserver 安装 Jumpserver 先决组件: cd /opt/jumpserver/jumpserver/requirements yum install $(cat rpm_requirements.txt) -y 安装 Jumpserver 组件: cd /opt/jumpserver/jumpserver/apps docker-compose up --build -d sudo docker exec -it jms_web /bin/bash ./jmsctl.sh install 4、配置Jumpserver 在安装了Jumpserver之后,需要进行一些基本配置,以使其开始工作。首先,我们需要创建一个超级管理员帐户,然后创建初次登录的普通用户。 cd /opt/jumpserver/jumpserver docker-compose exec jumpserver bash # 更换密码的操作可以选择跳过 ./jmsctl.sh init 5、访问Jumpserver 在Jumpserver配置完毕后,可以通过Web浏览器访问其管理控制台。使用任何支持HTML5 WebSockets和JavaScript的现代Web浏览器,无需特殊插件即可快速连接到Jumpserver。 http://your-server-ip:8080/ 6、使用Jumpserver 在成功配置并访问后,可以开始使用Jumpserver来管理和访问您的网络资产。为了开始使用Jumpserver,你首先需要为该系统添加网络资产,此步骤一般需要手动添加;其次,需要配置Jumpserver用户和访问权限;最后,使用Jumpserver连接到远程设备时,需要使用通过Jumpserver进行身份验证的登录凭据。 总结 本文介绍了在CentOS7上安装和部署Jumpserver的过程。完整的操作步骤包括安装依赖项、下载Jumpserver、安装Jumpserver、配置Jumpserver和使用Jumpserver。通过本文中所提供的指南,您将可以安全地部署Jumpserver,并开始使用它来帮助您管理您的网络资产和维护您的运维管理平台。 ### 回答3: Jumpserver是一款开源的堡垒机,能够帮助企业实现对敏感数据和服务器的安全管理。这里将介绍如何在CentOS 7上安装和部署Jumpserver。 1. 配置yum源 Jumpserver需要Python 3.6以上版本,因此我们需要添加epel和IUS软件仓库。执行以下命令: yum -y install https://centos7.iuscommunity.org/ius-release.rpm yum -y install epel-release 2. 安装必备组件 安装所需组件:git、openssl-devel、sqlite-devel、curl、gcc、nmap。 yum install -y git yum install -y openssl-devel sqlite-devel curl gcc nmap 3. 安装JumpServer 下载JumpServer: git clone https://github.com/jumpserver/jumpserver.git 安装JumpServer: cd jumpserver chmod +x setup.py ./setup.py install --yes 安装过程中可能需要等待一些时间,它会自动下载和安装所需的依赖。 4. 配置JumpServer 执行以下命令: cd /opt/jumpserver/config/ cp config_example.yml config.yml vim config.yml 在config.yml中进行配置。例如:修改Login、Secret和Database: SECRET_KEY: '**随机一个密码**' BOOTSTRAP_TOKEN: '**随机一个密码**' REDIS_HOST: '127.0.0.1' REDIS_PORT: 6379 REDIS_PASSWORD: '**自己设定**' DATABASE_ENGINE: mysql DATABASE_NAME: jumpserver DATABASE_USER: jumpserver DATABASE_PASSWORD: '**自己设定**' DATABASE_HOST: 127.0.0.1 DATABASE_PORT: 3306 TIME_ZONE: Asia/Shanghai LANG: en_US.UTF-8 保存文件。 5. 初始化数据库 执行以下命令: cd /opt/jumpserver/utils/ ./jms start all ./jms make_migrations ./jms migrate 6. 启动JumpServer 执行以下命令: cd /opt/jumpserver/utils/ ./jms start all 7. 测试访问 在浏览器访问JumpServer: http://ip:8080 输入之前配置的管理员账号和密码: 用户名: admin 密码: admin 至此,JumpServer安装部署完成,可以通过JumpServer实现对敏感数据和服务器的安全管理。

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

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

韩未零

你的鼓励将是我创作的最大动力

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

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

余额充值